angular - 运行 docker build 时 Npm run build 失败

标签 angular docker npm npm-install

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

注:
当我跑 npm run build在我的本地机器上它完美地工作试图改变 npm run build --aotnpm run buildDockerfile但问题仍然存在。

日志

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

文件
# 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

最佳答案

检查下面的日志后,我注意到问题是我使用的节点版本是 v10.15.1并且还有一个已弃用的软件包 fsevents@1.2.13 .来自 Dockerfile我试图安装与已弃用的软件包版本不兼容的最新节点版本。后来我把应用升级到 Angular 9 .此 version 中有几个新的突破性变化.也改变了 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

关于angular - 运行 docker build 时 Npm run build 失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62049777/

相关文章:

docker - Docker 上的 Websocket 和 nginx

docker - docker 镜像的默认命令

javascript - 从 Node.js 中的 JSON 数据中提取 JSON 字段

node.js - npm 脱网失败

node.js - Docker环境下禁止npm更新

css - 根据路由在组件中加载不同的样式

解析不同参数对象的Javascript泛型方法

angular - 通过项目的可观察属性将可观察数组过滤为另一个可观察数组(另一种类型)

java - 使用 Angular 参数上传文件

c# - 如何在asp.net core 2+中增加上传大小?请求的实体太大