5

I've done an upgrade of my Angular project from 8 to 9 by using the ng update tool. Locally (Windows) everything works fine, but when I'm trying to build the project in docker, I get the following error:

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

The 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:

"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"
}

Anything I can do to fix it? Images for Angular 8 were fine. I've tried different node images, but nothing helped...

Djent
  • 2,877
  • 10
  • 41
  • 66
  • When I was installing cli via `npm install`, the `ng` command wasn't present. I've fixed the explicit older version in my dockerfile, but it still doesn't work. – Djent Mar 20 '20 at 10:37
  • Thanks, I'm not node dev so I didn't know about the `npm run` and `npm ci`. Anyway, it still raises the same error after the change. – Djent Mar 20 '20 at 10:45
  • @Djent [What is the difference between “npm install” and “npm ci”?](https://stackoverflow.com/questions/52499617/what-is-the-difference-between-npm-install-and-npm-ci) – Liam Mar 20 '20 at 10:53
  • Have you tried to delete all `node_modules` and reinstall it by npm i ? – Shashikant Devani Mar 23 '20 at 06:21
  • It's a fresh docker container - there's no `node_modules` yet. – Djent Mar 23 '20 at 08:11
  • 2
    Can you try adding `"postinstall": "ngcc"` in your `package.json` file? – David Mar 23 '20 at 10:48
  • @David - that helped, thanks! You may want to post it as an answer to get the bounty reward. – Djent Mar 23 '20 at 11:33

1 Answers1

3

I'm not exactly sure what your issue is or what's causing it, but I did a quick search and stumbled upon this github issue. It concerns parallel builds (which I don't think is your case), but I thought it could still apply here since the error happens during the compilation of angular core.

The suggested workaround is to run the angular compatibility compiler (ngcc) as a postinstall script, instead of having the build trigger it itself.

Modify your package.json file and add the following to the scripts section:

"postinstall": "ngcc
Joe - GMapsBook.com
  • 15,787
  • 4
  • 23
  • 68
David
  • 33,444
  • 11
  • 80
  • 118