I came into a very strange issue yesterday. I have been working on an Angular project and deploying using docker. Everything works fine till yesterday, all of sudden I cannot build the docker image. The dockerfile is:
# Stage 1: Build the Angular application
FROM node:latest AS build
WORKDIR /app
COPY package.json package-lock.json ./
RUN npm install
COPY . .
RUN npm run build --prod
# Stage 2: Serve the application with Nginx
FROM nginx:latest
COPY --from=build /app/dist/gate /usr/share/nginx/html
COPY nginx.conf /etc/nginx/nginx.conf
# Copy self-signed SSL certificates
COPY certs /etc/nginx/certs
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
The docker error log is like:
4/6
RUN npm install
14.0s
npm warn deprecated [email protected]: Use your platform's native performance.now() and performance.timeOrigin.
npm warn deprecated [email protected]: Rimraf versions prior to v4 are no longer supported
npm warn deprecated [email protected]: This package is no longer supported. Please use @npmcli/package-json instead.
npm error Exit handler never called!
npm error This is an error with npm itself. Please report this error at:
npm error <https://github.com/npm/cli/issues>
npm error A complete log of this run can be found in: /root/.npm/_logs/2024-07-18T20_54_10_021Z-debug-0.log
build
5/6
COPY . .
1.0s
build
6/6
RUN npm run build --omit=dev
ERROR
0.0s
> [email protected] build
> ng build
sh: 1: ng: not found
Then I check the docker log of successful case, I notice that issue happens in the forth step. The normal log is like:
build
4/6
RUN npm install
16.0s
npm warn deprecated [email protected]: Use your platform's native performance.now() and performance.timeOrigin.
npm warn deprecated [email protected]: Use your platform's native DOMException instead
npm warn deprecated [email protected]: Use your platform's native atob() and btoa() methods instead
npm warn deprecated @npmcli/[email protected]: This functionality has been moved to @npmcli/fs
npm warn deprecated @wessberg/[email protected]: this package has been renamed to ts-evaluator. Please install ts-evaluator instead
npm warn deprecated @babel/[email protected]: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-unicode-property-regex instead.
npm warn deprecated @babel/[email protected]: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-async-generator-functions instead.
added 1089 packages, and audited 1090 packages in 15s
120 packages are looking for funding
run `npm fund` for details
10 vulnerabilities (4 moderate, 6 high)
To address all issues, run:
npm audit fix
Run `npm audit` for details.
npm notice
npm notice New patch version of npm available! 10.8.1 -> 10.8.2
npm notice Changelog: https://github.com/npm/cli/releases/tag/v10.8.2
npm notice To update run: npm install -g [email protected]
npm notice
build
5/6
COPY . .
8.0s
build
6/6
RUN npm run build --prod
32.0s
npm warn config production Use `--omit=dev` instead.
> [email protected] build
> ng build
- Generating browser application bundles (phase: setup)...
â Browser application bundle generation complete.
â Browser application bundle generation complete.
- Copying assets...
â Copying assets complete.
- Generating index html...
- Generating index html...
2 rules skipped due to selector errors:
.form-floating>~label -> Did not expect successive traversals.
.form-floating>~label -> Did not expect successive traversals.
â Index html generation complete.
Initial Chunk Files | Names | Raw Size | Estimated Transfer Size
main.486f9d20944b6cd4.js | main | 1.65 MB | 351.20 kB
styles.b35c1c689cedab16.css | styles | 329.66 kB | 32.46 kB
scripts.1ac6d0d02f230370.js | scripts | 77.70 kB | 20.87 kB
polyfills.4cb30b968c6ea108.js | polyfills | 33.03 kB | 10.66 kB
runtime.f0cd325c9a9e41bb.js | runtime | 988 bytes | 556 bytes
| Initial Total | 2.08 MB | 415.74 kB
Build at: 2024-07-18T13:14:22.046Z - Hash: 52b720b54f35c1fe - Time: 30454ms
Warning: /app/src/app/checklist/checklist-view/checklist-view.component.ts depends on 'moment'. CommonJS or AMD dependencies can cause optimization bailouts.
For more info see: https://angular.io/guide/build#configuring-commonjs-dependencies
I have tried many solutions found online but they all don’t work. I have tried to clear npm cache, delete node_modules folder, delete package-lock.json, reinstall again using npm install
, downgrade npm verstion to 8 even to 6. None of these solved the issue.
This issue comes out of nowhere, I did nothing about the project folder. I could successfully build 5 hours before the issue came.
The version info are
Angular CLI: 16.2.12
Node: 20.15.1 (Unsupported)
Package Manager: npm 10.8.2
OS: win32 x64
Angular: 16.2.12
... animations, cli, common, compiler, compiler-cli, core, forms
... localize, platform-browser, platform-browser-dynamic, router
Package Version
---------------------------------------------------------
@angular-devkit/architect 0.1602.12
@angular-devkit/build-angular 16.2.12
@angular-devkit/core 16.2.12
@angular-devkit/schematics 16.2.12
@angular/cdk 16.2.14
@angular/material 16.2.14
@schematics/angular 16.2.12
rxjs 7.8.1
typescript 5.1.6
zone.js 0.13.3
Warning: The current version of Node (20.15.1) is not supported by Angular.
Can someone help with this?
5
You shouldn’t use the latest
tag of the node image with Angular projects. Angular only supports the LTS version. In the stable channel some changes might be made which Angular first needs to adapt for. Use the lts
tag instead:
FROM node:lts
1