错误“process.nextTick(() => { throw err; });”在 docker 上构建 Angular 图像时

问题描述 投票:0回答:1

我有以下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

两周前,当我运行

docker build -t imgTest .
时,一切正常,图像已成功构建。但是今天,当我再次尝试运行这个 dockerfile 时,我刚刚收到以下错误:

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

我的角度应用程序非常基础。我的

app.component.html

中只有这个 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>

导致此错误的原因可能是什么?

node.js angular docker npm docker-image
1个回答
1
投票

Node 始终指最新的可用节点版本,目前为 21.x.x。正如这里提到的,Node 21 目前不兼容从 dart 编译为 js 的程序。

你需要改变

FROM node:latest AS build

FROM node:20-alpine AS build

一般情况下,您应该使用特定的版本来避免此类问题。

© www.soinside.com 2019 - 2024. All rights reserved.