在运行docker build时,npm run build失败

9

在运行docker build .时出现错误。问题出在docker运行npm install -f时,我最初将命令更改为npm install,但问题仍然存在。日志太长了,无法在此处发布更多详细信息,请单击此处查看。下面是日志的一部分,最后一部分日志未能完成构建。我还包括了Dockerfile

注意: 当我在本地计算机上运行npm run build时,它完美运行,尝试在Dockerfile中将npm run build --aot更改为npm run build,但问题仍然存在。

日志

Generating ES5 bundles for differential loading...
An unhandled exception occurred: [BABEL] /app/dist/e-county/src-app-receipting-receipting-module-es2015.js: Could not find plugin "proposal-numeric-separator". Ensure there is an entry in ./available-plugins.js for it. (While processing: "/app/node_modules/@babel/preset-env/lib/index.js")
See "/tmp/ng-j8ToFT/angular-errors.log" for further details.
npm ERR! code ELIFECYCLE
npm ERR! syscall spawn
npm ERR! file sh
npm ERR! errno ENOENT
npm ERR! e-county@0.0.0 build: `node --max_old_space_size=4096 node_modules/@angular/cli/bin/ng build`
npm ERR! spawn ENOENT
npm ERR! 
npm ERR! Failed at the e-county@0.0.0 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2020-05-27T17_41_05_761Z-debug.log
The command '/bin/sh -c npm run build --aot' returned a non-zero code: 1

Dockerfile

# stage 1
FROM node:latest as node

WORKDIR /app

COPY . .


RUN npm i -f && npm audit fix

RUN npm run build --aot

# stage 2
FROM nginx:alpine


RUN rm -rf /usr/share/nginx/html/*

COPY  --from=node /app/nginx/*  /etc/nginx/conf.d/default.conf
COPY --from=node /app/dist/e-county /usr/share/nginx/html

1
可能是重复的问题,参见 https://dev59.com/3lIH5IYBdhLWcg3wKqPW - HackLab
2个回答

5

检查以下日志后,我发现问题出在我使用的节点版本上,即v10.15.1,并且还有一个已弃用的包fsevents@1.2.13。从我的Dockerfile中,我尝试安装最新的节点版本,但与弃用的包版本不兼容。然后我将应用程序升级到Angular 9。这个版本中有几个新的破坏性变化。我也更改了Dockerfile,不需要强制使用npm i -f进行安装或运行npm audit fix,因为所有依赖项都是最新的且已更新。值得一提的是,始终检查您应用程序中的依赖项是否是最新的,并从包文档中找出是否涉及任何破坏性变化,这将节省您大量修复依赖项问题的时间。

npm WARN deprecated fsevents@1.2.13: fsevents 1 will break on node v14+ and could be using insecure binaries. Upgrade to fsevents 2.
npm WARN notsup Unsupported engine for watchpack-chokidar2@2.0.0: wanted: {"node":"<8.10.0"} (current: {"node":"10.15.1","npm":"6.12.0"})
npm WARN notsup Not compatible with your version of node/npm: watchpack-chokidar2@2.0.0
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@^1.2.7 (node_modules/watchpack-chokidar2/node_modules/chokidar/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.13: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@^1.2.7 (node_modules/webpack-dev-server/node_modules/chokidar/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.13: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
npm WARN notsup Unsupported engine for watchpack-chokidar2@2.0.0: wanted: {"node":"<8.10.0"} (current: {"node":"10.15.1","npm":"6.12.0"})
npm WARN notsup Not compatible with your version of node/npm: watchpack-chokidar2@2.0.0
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@^1.2.7 (node_modules/watchpack-chokidar2/node_modules/chokidar/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.13: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@^1.2.7 (node_modules/webpack-dev-server/node_modules/chokidar/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.13: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
npm WARN @angular/animations@8.2.14 requires a peer of @angular/core@8.2.14 but none is installed. You must install peer dependencies yourself.
npm WARN @angular-devkit/build-angular@0.901.7 requires a peer of @angular/compiler-cli@>=9.0.0 < 10 but none is installed. You must install peer dependencies yourself.
npm WARN @angular-devkit/build-angular@0.901.7 requires a peer of typescript@>=3.6 < 3.9 but none is installed. You must install peer dependencies yourself.
npm WARN @ngtools/webpack@9.1.7 requires a peer of @angular/compiler-cli@>=9.0.0 < 10 but none is installed. You must install peer dependencies yourself.
npm WARN @ngtools/webpack@9.1.7 requires a peer of typescript@>=3.6 < 3.9 but none is installed. You must install peer dependencies yourself.
npm WARN sass-loader@8.0.2 requires a peer of node-sass@^4.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN sass-loader@8.0.2 requires a peer of fibers@>= 3.1.0 but none is installed. You must install peer dependencies yourself.
npm WARN webpack-subresource-integrity@1.4.0 requires a peer of html-webpack-plugin@^2.21.0 || ~3 || >=4.0.0-alpha.2 <5 but none is installed. You must install peer dependencies yourself.

+ @angular-devkit/build-angular@0.901.7
added 254 packages from 127 contributors, removed 28 packages, updated 169 packages and moved 25 packages in 132.099s
fixed 4 of 9 vulnerabilities in 2093 scanned packages
  3 package updates for 5 vulnerabilities involved breaking changes
  (use `npm audit fix --force` to install breaking changes; or refer to `npm audit` for steps to fix these manually)

更新后的 Dockerfile

# stage 1
FROM node:latest as node

WORKDIR /app

COPY . .

RUN npm i 

RUN npm run build --prod

# stage 2
FROM nginx:alpine

RUN rm -rf /usr/share/nginx/html/*

COPY  --from=node /app/nginx/*  /etc/nginx/conf.d/default.conf
COPY --from=node /app/dist/e-county /usr/share/nginx/html

0
请检查 angular.json 中的 "outputPath"。在 COPY --from=node 中传递的路径需要保持一致。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接