5

I have a jenkins job that runs on a centos 7 container. Once the container is up the jenkins job runs a script that executes

 npm install -g @angular/cli

This has worked for about an year but today it started failing:

 /usr/bin/ng -> /usr/lib/node_modules/@angular/cli/bin/ng
 > @angular/[email protected] postinstall /usr/lib/node_modules/@angular/cli
 > node ./bin/postinstall/script.js
 /usr/lib/node_modules/@angular/cli/bin/postinstall/analytics-prompt.js:8
 (async () => {
 ^
 SyntaxError: Unexpected token (
 at createScript (vm.js:56:10)
 at Object.runInThisContext (vm.js:97:10)
 at Module._compile (module.js:549:28)
 at Object.Module._extensions..js (module.js:586:10)
 at Module.load (module.js:494:32)
 at tryModuleLoad (module.js:453:12)
 at Function.Module._load (module.js:445:3)
 at Module.require (module.js:504:17)
 at require (internal/module.js:20:19)
 at Object.<anonymous> (/usr/lib/node_modules/@angular/cli/bin/postinstall/script.js:5:1)
 npm ERR! Linux 3.10.0-957.1.3.el7.x86_64
 npm ERR! argv "/usr/bin/node" "/usr/bin/npm" "install" "-g" "@angular/cli"
 npm ERR! node v6.16.0
 npm ERR! npm  v3.10.10
 npm ERR! code ELIFECYCLE
 npm ERR! @angular/[email protected] postinstall: `node ./bin/postinstall/script.js`
 npm ERR! Exit status 1
 npm ERR!
 npm ERR! Failed at the @angular/[email protected] postinstall script 'node ./bin/postinstall/script.js'.
 npm ERR! Make sure you have the latest version of node.js and npm installed.
 npm ERR! If you do, this is most likely a problem with the @angular/cli package,
 npm ERR! not with npm itself.
 npm ERR! Tell the author that this fails on your system:
 npm ERR!     node ./bin/postinstall/script.js
 npm ERR! You can get information on how to open an issue for this project with:
 npm ERR!     npm bugs @angular/cli
 npm ERR! Or if that isn't available, you can get their info via:
 npm ERR!     npm owner ls @angular/cli
 npm ERR! There is likely additional logging output above.
 npm ERR! Please include the following file with any support request:
 npm ERR!     /app/capman-fe/npm-debug.log

My packages.json is this:

{
  "name": "pman-fe",
  "version": "0.0.0",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
... omitted for brevity ...
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "^0.6.8",
    "@angular/cli": "^6.0.8",
    "@angular/compiler-cli": "^6.0.3",
    "@angular/language-service": "^6.0.3",
    "@types/d3": "^5.7.1",
    "@types/jasmine": "~2.8.6",
    "@types/jasminewd2": "~2.0.3",
    "@types/node": "~8.9.4",
    "codelyzer": "~4.2.1",
    "jasmine-core": "~2.99.1",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~1.7.1",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage-istanbul-reporter": "~2.0.0",
    "karma-jasmine": "~1.1.1",
    "karma-jasmine-html-reporter": "^0.2.2",
    "protractor": "^5.4.1",
    "ts-node": "~5.0.1",
    "tslint": "~5.9.1",
    "typescript": "~2.7.2"
  }
}
5
  • This is the result of requiring always the latest version of a library. Commented Jun 25, 2019 at 15:57
  • Ok so how do I fix it. Commented Jun 25, 2019 at 16:18
  • 1
    I'm having this issue and I am just trying to do a fresh install of the Angular CLI. Is their package borked? Commented Jun 25, 2019 at 20:40
  • @DavidPrice I install my npm from an rpm via yum are you using Redhat or Centos? If so try installing the yum repo and use the rpm from there. Commented Jun 25, 2019 at 21:09
  • I'm on windows. Sorry I see you are on Linux. Maybe my node/npm is bad? I have never installed angular CLI on this machine. Commented Jun 25, 2019 at 21:13

3 Answers 3

3

I was able to solve this error. The problem was that when I installed npm I simply executed: yum -y install npm. I guess the yum repo that the container I have to use doesn't have an up to date copy of the npm rpm. So I changed how I install npm. Now I do this:

yum install -y gcc-c++ make
curl -sL https://rpm.nodesource.com/setup_10.x | bash -
yum -y install nodejs
node -v
npm -v
npm install -g @angular/cli

as per https://tecadmin.net/install-latest-nodejs-and-npm-on-centos/

Sign up to request clarification or add additional context in comments.

3 Comments

Like I said, if you require the latest version of any library, be it in yum or npm you will eventually encounter such errors. This is why software follow semver. Stick to fixed versions your software is written in. Eg. @angular/cli@^8.0
People may want to look at this documentation: docs.npmjs.com/about-semantic-versioning
This way the day 9.0 is released you won't have to wonder why did your app break all of a sudden ;)
1

replace

npm install -g @angular/cli

on

npm install -g @angular/cli@~8.0.0

current 8.0.4 version @angular/cli bug with dependency

use ~8.0.0 or less (Ideal for version to match with package.json)

1 Comment

I have the same error on CentOS. I have the latest node and npm (v6.17.1 and v3.10.10 respectively). I tried to install 8.0.0 like you said. Same error. Error code: ELIFECYCLE. Failed at the @angular/[email protected] postinstall script 'node ./bin/postinstall/script.js'.
1

I just encountered the same error on Windows: turns out I had a super old version (v.6.11.0) of Node, so I would just try updating the local version of Node on your centos machine (or whatever environment you are on). Note this will also update your version of npm (most likely).

1 Comment

Thanks @ivarcode. Although I faced this issue on mac. I wonder why an older version get installed on my system when i did brew install node same as yours (v.6.11.0). Due to which my angular was causing the same issue. I then installed node from the package which I downloaded from nodejs.org/en

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.