我在 NodeJs 应用程序中有一个 Angular 应用程序。
我的 Dockerfile 如下所示:
FROM node:12.14.1-alpine
WORKDIR /app
COPY . ./
WORKDIR /app/ng-app
RUN npm install && npm run build
WORKDIR /app
# npm install and delete everything from the ng-app folder except the out directory.
RUN npm install
RUN find ./ng-app -depth -mindepth 1 -maxdepth 1 -not -name out -exec rm -rf '{}' \;
EXPOSE 3000
CMD [ "npm", "start" ]
当我在本地开发环境中运行
docker build -t my-app .
命令时,一切正常,没有任何问题。
但是,当在 AWS CodeBuild 管道中执行相同的命令时,它会在
npm run build
工作目录内运行 /app/ng-app
时引发错误。
Compiling @angular/flex-layout/extended : es2015 as esm2015
Compiling @angular/flex-layout/flex : es2015 as esm2015
Compiling @angular/flex-layout/grid : es2015 as esm2015
Compiling @angular/flex-layout : es2015 as esm2015
Compiling ngx-scrollbar/smooth-scroll : es2015 as esm2015
Compiling ngx-scrollbar : es2015 as esm2015
✔ Browser application bundle generation complete.
✔ Browser application bundle generation complete.
Warning: /app/ng-app/node_modules/canvg/lib/index.es.js depends on 'core-js/modules/es.array.index-of.js'. CommonJS or AMD dependencies can cause optimization bailouts.
For more info see: https://angular.io/guide/build#configuring-commonjs-dependencies
Warning: /app/ng-app/node_modules/canvg/lib/index.es.js depends on 'core-js/modules/es.array.iterator.js'. CommonJS or AMD dependencies can cause optimization bailouts.
For more info see: https://angular.io/guide/build#configuring-commonjs-dependencies
Warning: /app/ng-app/src/app/board/service/paper.service.ts depends on 'tree-util'. CommonJS or AMD dependencies can cause optimization bailouts.
For more info see: https://angular.io/guide/build#configuring-commonjs-dependencies
Error: Optimization error [main.js]: Error: The service was stopped
at /app/ng-app/node_modules/@angular-devkit/build-angular/node_modules/esbuild/lib/main.js:1276:29
at /app/ng-app/node_modules/@angular-devkit/build-angular/node_modules/esbuild/lib/main.js:629:9
at Socket.afterClose (/app/ng-app/node_modules/@angular-devkit/build-angular/node_modules/esbuild/lib/main.js:607:7)
at Socket.emit (events.js:228:7)
at endReadableNT (_stream_readable.js:1185:12)
at processTicksAndRejections (internal/process/task_queues.js:81:21)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] build: `ng build --output-hashing none`
npm ERR! Exit status 1
本地开发环境下的 Angular CLI 版本详细信息如下:
Angular CLI: 12.2.17
Node: 12.14.1
Package Manager: npm 6.13.4
OS: darwin x64
Angular: 12.2.16
... animations, common, compiler, compiler-cli, core, forms
... platform-browser, platform-browser-dynamic, router
Package Version
---------------------------------------------------------
@angular-devkit/architect 0.1202.17
@angular-devkit/build-angular 12.2.17
@angular-devkit/core 12.2.17
@angular-devkit/schematics 12.2.17
@angular/cdk 12.2.13
@angular/cli 12.2.17
@angular/flex-layout 12.0.0-beta.35
@angular/material 12.2.13
@schematics/angular 12.2.17
rxjs 6.6.7
typescript 4.3.5