【发布时间】:2019-06-26 13:29:56
【问题描述】:
在 Azure Dev Ops Pipelines 上构建中型 Angular 7 项目时遇到问题。所以我创建了一个最小的项目来重新创建问题。
使用 Angular CLI (7.2.4) 我创建了一个新项目
ng new minimal-app
它可以在本地构建,也可以在 Azure 上构建。我编辑了 app.component.ts 以使用我的 UserModel,第 2、11 和 14 行
import {Component} from '@angular/core';
import {UserModel} from '../Models/User.model';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
title = 'minimal-app';
user = new UserModel();
constructor() {
this.user.name = 'Jo';
}
}
User.model.ts 文件包含
export class UserModel {
id: number;
name: string;
}
这也可以在本地和 Azure 上编译。尝试添加嵌套模型时会出现问题,请参阅 Action.model.ts
export class ActionModel {
id: number;
datetime: string;
}
并更改用户模型
import {ActionModel} from './Action.Model';
export class UserModel {
id: number;
name: string;
actions: ActionModel[];
}
这在本地工作,但在 Azure Dev Ops 我得到
ERROR in src/Models/User.model.ts(1,27): error TS2307: Cannot find module './Action.Model'.
##[error]Bash exited with code '1'
我没有更改任何 Angular 配置文件,它们都是新项目的默认配置。天蓝色管道 yml 是
# Node.js with Angular
# Build a Node.js project that uses Angular.
# Add steps that analyze code, save build artifacts, deploy, and more:
# https://docs.microsoft.com/azure/devops/pipelines/languages/javascript
trigger:
- master
pool:
vmImage: 'ubuntu-latest'
steps:
- task: NodeTool@0
inputs:
versionSpec: '10.x'
displayName: 'Install Node.js'
- script: |
npm install -g @angular/cli
npm install
ng build --prod
displayName: 'npm install and build'
【问题讨论】:
-
也许尝试将
.添加到./Action.Model(../Action.Model) -
@ShaykiAbramczyk 遗憾的是,这无济于事:(尽管这些模型彼此位于同一个文件夹中,所以我想这是一个远射,但我对此感到困惑
-
您可以在尝试构建应用程序时修复它通过使用 baseHref 和 deployUrl
标签: angular azure-devops