ng not found error when building Angular project using dockerfile

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

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật