Error "process.nextTick(() => { throw err; });" when building Angular image on docker

489 Views Asked by At

I have the following dockerfile

FROM node:latest AS build

WORKDIR /app

COPY . .

RUN npm install

RUN npm run build

FROM nginx:alpine

COPY --from=build /app/dist/website-k8s/ /usr/share/nginx/html

EXPOSE 80

Two weeks ago, when I ran the docker build -t imgTest . all works fine and the image was successfully built. But today, when I tried to run this dockerfile again, I just received the following error:

Node.js version v21.0.0 detected.
Odd numbered Node.js versions will not enter LTS status and should not be used for production. For more information, please see https://nodejs.org/en/about/releases/.
- Generating browser application bundles (phase: setup)...
#12 9.196 node:internal/event_target:1084
  process.nextTick(() => { throw err; });
                           ^
TypeError [Error]: Cannot read properties of undefined (reading 'indexOf')
    at /app/node_modules/sass/sass.dart.js:104395:12
    at Object.applyHooksTransformer (/app/node_modules/sass/sass.dart.js:1860:14)
    at Object.initHooks (/app/node_modules/sass/sass.dart.js:1840:251)
    at Object.initNativeDispatchContinue (/app/node_modules/sass/sass.dart.js:1806:9)
    at Object.initNativeDispatch (/app/node_modules/sass/sass.dart.js:1800:9)
    at Object.getNativeInterceptor (/app/node_modules/sass/sass.dart.js:25385:13)
    at Object.getInterceptor$x (/app/node_modules/sass/sass.dart.js:25634:16)
    at Object.set$compile$x (/app/node_modules/sass/sass.dart.js:25698:16)
    at Object.main (/app/node_modules/sass/sass.dart.js:21090:9)
    at main2 (/app/node_modules/sass/sass.dart.js:22875:9)
#12 9.200 Node.js v21.0.0

My angular application is really basic. I have only this HTML file in the app.component.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>SimpleCalc</title>
</head>
<body>
    <h1 class="title">SIMPLE CALCULATOR</h1>

    <div class="calc-container">
        <input class="calc-container--input" type="number">
        <input class="calc-container--input" type="number">

        <button *ngIf="this.num1 && this.num2" class="calc-container--btn">Get result</button>
    </div>
</body>
</html>

What could be the cause of this error?

1

There are 1 best solutions below

0
On

Node always refers to the latest available node version, which is right now 21.x.x. As mentioned here, Node 21 is currently not compatible with programs compiled from dart to js.

You need to change

FROM node:latest AS build

To

FROM node:20-alpine AS build

Generally, you should use a specific version to avoid such problems.