Bitbucket Angular npm 运行构建失败

Posted

技术标签:

【中文标题】Bitbucket Angular npm 运行构建失败【英文标题】:Bitbucket Angular npm run build fails 【发布时间】:2020-10-31 08:49:13 【问题描述】:

我正在尝试在 Bitbucket 上设置构建管道。我正在使用一个全新的 Angular 项目。 到目前为止它看起来像这样

- step:
    name: build frontend
    caches:
      - node
    condition:
      changesets:
        includePaths:
          - "frontend/src/deguvino-portal/**"
    image: node:14.5.0
    script:
      - npm install
      - npm install -g @angular/cli          
      - npm install -g npm@latest
      - npm install -g @angular-devkit/build-angular
      - npm run build --prod --prefix ./frontend/src/deguvino-portal/

它在npm run build 命令上一直失败并出现错误

An unhandled exception occurred: Cannot find module '@angular-devkit/build-angular/package.json'
Require stack:
- /usr/local/lib/node_modules/@angular/cli/node_modules/@angular-devkit/architect/node/node-modules-architect-host.js
- /usr/local/lib/node_modules/@angular/cli/node_modules/@angular-devkit/architect/node/index.js
- /usr/local/lib/node_modules/@angular/cli/models/architect-command.js
- /usr/local/lib/node_modules/@angular/cli/commands/build-impl.js
- /usr/local/lib/node_modules/@angular/cli/node_modules/@angular-devkit/schematics/tools/export-ref.js
- /usr/local/lib/node_modules/@angular/cli/node_modules/@angular-devkit/schematics/tools/index.js
- /usr/local/lib/node_modules/@angular/cli/utilities/json-schema.js
- /usr/local/lib/node_modules/@angular/cli/models/command-runner.js
- /usr/local/lib/node_modules/@angular/cli/lib/cli/index.js
- /usr/local/lib/node_modules/@angular/cli/lib/init.js
- /usr/local/lib/node_modules/@angular/cli/bin/ng
See "/tmp/ng-nTDaRU/angular-errors.log" for further details.
npm ERR! code ELIFECYCLE
npm ERR! syscall spawn
npm ERR! file sh
npm ERR! errno ENOENT
npm ERR! deguvino-portal@0.0.0 build: `ng build`
npm ERR! spawn ENOENT
npm ERR! 
npm ERR! Failed at the deguvino-portal@0.0.0 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm WARN Local package.json exists, but node_modules missing, did you mean to install?
npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2020-07-10T14_51_37_386Z-debug.log

关于如何修复它的任何建议? 附:我使用的是npm run build 而不是ng build,因为我的源不在根文件夹中,而是在frontend/src/deguvino-portal/ 目录下,并且我确实找到了一种为ng build 指定目录的方法。

【问题讨论】:

您找到解决方案了吗?我也面临同样的问题。你能帮忙吗 是的。请在下面查看我的答案。 【参考方案1】:

我所要做的就是使用- cd ./frontend/src/deguvino-portal 导航到根文件夹,进行安装和构建,然后返回。完整的脚本:

 - step:
    name: build frontend
    caches:
      - node
    image: node:14.5.0
    script:        
      - cd ./frontend/src/deguvino-portal
      - npm install
      - npm run build-prod
      - apt-get update
      - apt-get install zip -y
      - cd ./dist/deguvino-portal
      - zip -r PublishOutputUI.zip .
      - pipe: microsoft/azure-web-apps-deploy:1.0.3
        variables:
         AZURE_APP_ID: $AZURE_APP_ID
         AZURE_PASSWORD: $AZURE_PASSWORD
         AZURE_TENANT_ID: $AZURE_TENANT_ID
         AZURE_RESOURCE_GROUP: '****'
         AZURE_APP_NAME: '*****'
         ZIP_FILE: 'PublishOutputUI.zip'
    artifacts: 
      - PublishOutputUI.zip

【讨论】:

以上是关于Bitbucket Angular npm 运行构建失败的主要内容,如果未能解决你的问题,请参考以下文章

npm run build在bitbucket管道中失败,因为它无法解析某些文件

Yarn 包管理器:从私有 Bitbucket 存储库安装依赖项

运行 Angular 2 快速入门时解决或修复 Linux 上的 NPM lite-server 错误

Angular Browserslist:caniuse-lite 已过时。请运行下一个命令`npm update`

仅当子目录中的文件已更改时,才运行VSTS构建任务以运行“npm build”

npm audit fix angular 10.0.1 后的错误