角构建无法找到具有相对路径的模块(在Azure开发运营上) [英] Angular build cannot find module with relative path (on azure dev ops)

查看:41
本文介绍了角构建无法找到具有相对路径的模块(在Azure开发运营上)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法在Azure Dev Ops Pipelines上构建中型Angular 7项目.因此,我创建了一个最小的项目来重新创建问题.

I have a problem getting a mid-sized Angular 7 project to build on Azure Dev Ops Pipelines. So I created a minimal project to recreate the issue.

使用Angular CLI(7.2.4)我创建了一个新项目

Using Angular CLI (7.2.4) I created a new project

ng new minimal-app

它可以在本地构建,也可以在Azure上构建.我编辑了app.component.ts以使用我的UserModel(第2、11和9行).14

It builds locally and on Azure just fine. I edited app.component.ts to use my UserModel, lines 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文件包含

the User.model.ts file contains

export class UserModel {
  id: number;
  name: string;
}

这也可以在本地和Azure上编译.尝试添加嵌套模型时会出现问题,请参见Action.model.ts

This also compiles on local and Azure just fine. The issue comes when trying to add a nested model, see Action.model.ts

export class ActionModel {
  id: number;
  datetime: string;
}

并更改UserModel

and changing the UserModel

import {ActionModel} from './Action.Model';

export class UserModel {
  id: number;
  name: string;
  actions: ActionModel[];
}

这在本地有效,但是我在Azure Dev Ops上获得

This works locally but on Azure Dev Ops I get

ERROR in src/Models/User.model.ts(1,27): error TS2307: Cannot find module './Action.Model'.

##[error]Bash exited with code '1'

我没有更改任何Angular配置文件,它们都是新项目的默认设置.天青管道yml是

I've not changed any Angular config files, they are all default for new project. The azure pipelines yml is

# 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'

推荐答案

根据您的代码,我注意到您正在使用区分大小写的 Ubuntu 代理.

According to your code, I notice that you are using Ubuntu agent which is case sensitive.

而且,您配置的模块是" Action.model ",但是在导入时,您使用的名称是" Action.Model ".对于ubuntu和linux,由于区分大小写,因此无法将其标识为相同.

And also, the module you configured is "Action.model", but while import, the name you used is "Action.Model". For ubuntu and linux, it could not be identified as same because of its case sensitive.

我认为您可以使用不区分大小写的Windows在本地执行这些脚本.这就是为什么它在本地工作的原因.

I think you may execute these script locally with windows which is case insensitive. That's why it's worked locally.

因此,要解决此问题,您需要将脚本更改为:

So, for solved, you need to change your script as :

import {ActionModel} from './Action.model';

export class UserModel {
  id: number;
  name: string;
  actions: ActionModel[];
}

这篇关于角构建无法找到具有相对路径的模块(在Azure开发运营上)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆