1

在我的 NestJS 项目中,在本地构建和运行是可行的,但是在我的 Azure 管道中构建相同的代码时,由于在命令启动时找不到某些模块,它最近开始失败npm run build。当我在本地运行命令时,没有任何问题并且可以正确构建。

有许多模块可以正确找到(或没有给出错误),那么为什么不呢?您可以在 Imgur 上的此图像中找到我的文件布局图像,并显示相关文件。所有的类都被声明为export class ... {}并且它们中的大多数也被导入到 AppModule 中,它们不会给出错误。

管道布局(相关部分):

trigger:
  - master
  - dev

pool:
  vmImage: 'ubuntu-latest'

steps:
- task: NodeTool@0
  displayName: 'Install Node 12'
  inputs:
    versionSpec: 12.0.0

- script: |
    npm install -g typescript
    npm install
    npm test
  displayName: 'run tests'

- script: |
    npm run build
  displayName: 'build dist folder'

管道日志:(相关部分)

Generating script.
Script contents:
npm run build
========================== Starting Command Output ===========================

> fleetbot-nestjs@0.0.1 prebuild /home/vsts/work/1/s
> rimraf dist


> fleetbot-nestjs@0.0.1 build /home/vsts/work/1/s
> nest build

10 import { MailerService } from "../../Mailer/mailer.service";
                                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/app.module.ts:13:30 - error TS2307: Cannot find module './Mailer/mailer.module'.

13 import { MailerModule } from './Mailer/mailer.module';
                                ~~~~~~~~~~~~~~~~~~~~~~~~
src/app.module.ts:14:34 - error TS2307: Cannot find module './Mailer/mailer.controller'.

14 import { MailerController } from './Mailer/mailer.controller';
                                    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/app.module.ts:15:33 - error TS2307: Cannot find module './Teams/teams.controller'.

15 import { TeamsController } from './Teams/teams.controller';
                                   ~~~~~~~~~~~~~~~~~~~~~~~~~~
src/app.module.ts:16:37 - error TS2307: Cannot find module './Chatlayer/chatlayer.controller'.

16 import { ChatlayerController } from './Chatlayer/chatlayer.controller';
                                       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/mailer/mailer.module.ts:4:33 - error TS2307: Cannot find module '../Mailer/mailer.provider'.

4 import { mailerProviders } from "../Mailer/mailer.provider";
                                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~

Found 9 error(s).

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! fleetbot-nestjs@0.0.1 build: `nest build`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the fleetbot-nestjs@0.0.1 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/vsts/.npm/_logs/2020-06-03T18_00_47_946Z-debug.log

##[error]Bash exited with code '1'.
Finishing: build dist folder
4

2 回答 2

3

它通过将构建代理更改为 macOS 来工作。确实一定是某处错误的区分大小写。

于 2020-06-29T09:57:15.920 回答
1

我对 bitbucket 管道也有类似的问题。这是因为我已经编写npm installnpm run build不同的步骤,因此无法找到下一步所需的模块。

于 2021-04-14T11:41:52.227 回答