从8升级到9后无法构建Angular项目

5

我使用ng update工具将我的Angular项目从8升级到9。在本地(Windows)一切正常,但是当我尝试在docker中构建该项目时,我遇到了以下错误:

Step 6/11 : RUN npm run build
  ---> Running in d60f739a56f6
 > check-it-frontend@0.0.0 build /app
 > ng build --prod
 Compiling @angular/core : es2015 as esm2015
 ERROR in EINVAL: invalid argument, rename '/app/node_modules/@angular/core/core.d.ts' -> '/app/node_modules/@angular/core/core.d.ts.__ivy_ngcc_bak'
 npm ERR! code ELIFECYCLE
 npm ERR! errno 1
 npm ERR! check-it-frontend@0.0.0 build: `ng build --prod`
 npm ERR! Exit status 1
 npm ERR! 
 npm ERR! Failed at the check-it-frontend@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-03-20T11_44_02_696Z-debug.log
 The command '/bin/sh -c npm run build' returned a non-zero code: 1

Dockerfile文件如下:
FROM node:13.10.1-stretch as base

RUN apt-get update -qq && apt-get install -y build-essential

ADD . /app
WORKDIR /app

RUN npm ci
RUN npm run build

依赖项:

"dependencies": {
  "@angular/animations": "^9.0.7",
  "@angular/cdk": "^8.2.3",
  "@angular/common": "^9.0.7",
  "@angular/compiler": "^9.0.7",
  "@angular/core": "^9.0.7",
  "@angular/forms": "^9.0.7",
  "@angular/material": "^8.2.3",
  "@angular/platform-browser": "^9.0.7",
  "@angular/platform-browser-dynamic": "^9.0.7",
  "@angular/router": "^9.0.7",
  "core-js": "^2.4.1",
  "rxjs": "^6.5.4",
  "rxjs-compat": "^6.0.0-rc.0",
  "tslib": "^1.10.0",
  "zone.js": "~0.10.2"
},
"devDependencies": {
  "@angular-devkit/build-angular": "~0.900.7",
  "@angular/cli": "^9.0.7",
  "@angular/compiler-cli": "^9.0.7",
  "@angular/language-service": "^9.0.7",
  "@types/jasmine": "~2.8.3",
  "@types/jasminewd2": "~2.0.2",
  "@types/node": "^12.11.1",
  "codelyzer": "^5.1.2",
  "jasmine-core": "~2.8.0",
  "jasmine-spec-reporter": "~4.2.1",
  "karma": "~2.0.0",
  "karma-chrome-launcher": "~2.2.0",
  "karma-coverage-istanbul-reporter": "^1.2.1",
  "karma-jasmine": "~1.1.0",
  "karma-jasmine-html-reporter": "^0.2.2",
  "node-sass": "^4.13.1",
  "protractor": "~5.1.2",
  "ts-node": "~4.1.0",
  "tslint": "~5.9.1",
  "typescript": "~3.7.5"
}

有什么办法可以解决吗?Angular 8 的图片很好,但是我尝试了不同的节点映像,但没有帮助...


当我通过npm install安装cli时,ng命令不存在。我已经在我的dockerfile中修复了明确的旧版本,但它仍然无法工作。 - Djent
谢谢,我不是Node开发人员,所以我不知道npm runnpm ci。无论如何,在更改之后它仍然引发相同的错误。 - Djent
你尝试过删除所有的 node_modules 并通过 npm i 重新安装吗? - Shashikant Devani
这是一个全新的Docker容器 - 还没有node_modules - Djent
2
你可以尝试在package.json文件中添加"postinstall": "ngcc"吗? - David
显示剩余2条评论
1个回答

3
我不确定您的问题是什么或是什么导致了它,但我进行了快速搜索并偶然发现了这个 github问题。 它涉及到并行构建(我认为这不是您的情况),但我认为它仍然适用于此,因为错误发生在angular核心编译期间。
建议的解决方法是将angular兼容编译器(ngcc)作为一个postinstall脚本运行,而不是让构建触发它自己。
修改您的package.json文件,并将以下内容添加到scripts部分:
"postinstall": "ngcc

有关信息:https://angular.io/guide/ivy#ivy-and-universalapp-shell - xdeepakv

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