A J Qarshi
A J Qarshi

Reputation: 2992

Angular - Optimization error [main.js]: Error: The service was stopped

I have an angular application inside the NodeJs app.

My Dockerfile looks like below:

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" ]

When I run the docker build -t my-app . command in my local development environment, everything works fine without any issues.

However, when the same command executes in the AWS CodeBuild pipeline, it throws an error while running the npm run build inside the /app/ng-app working directory.

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

The Angular CLI version details on the local development environment are shown below:

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

A very similar issue has been reported here but in my case the node versions seem fine.

Upvotes: 1

Views: 2893

Answers (0)

Related Questions