Search code examples
node.jsangularangular-clinvm

unable to install angular cli globally in nodejs 18.15.0


Trying to setup latest angular version using NVM and node latest version

I installed node version 18.15.0 and then try to do npm i -g @angular/cli

I am getting this below error. Anyone faced similar issue?

D:\mydevs>node -v
v18.15.0

D:\mydevs>npm i -g @angular/cli


ERROR: npm v9.5.0 is known not to run on Node.js v18.15.0. You'll need to upgrade
to a newer Node.js version in order to use this version of npm. This version of
npm supports the following node versions: `^14.17.0 || ^16.13.0 || >=18.0.0`. You
can find the latest version at https://nodejs.org/.

ERROR:
C:\nvm\v18.15.0\node_modules\npm\node_modules\@npmcli\arborist:1
../../workspaces/arborist
^

SyntaxError: Unexpected token '.'
    at internalCompileFunction (node:internal/vm:73:18)
    at wrapSafe (node:internal/modules/cjs/loader:1176:20)
    at Module._compile (node:internal/modules/cjs/loader:1218:27)
    at Module._extensions..js (node:internal/modules/cjs/loader:1308:10)
    at Module.load (node:internal/modules/cjs/loader:1117:32)
    at Module._load (node:internal/modules/cjs/loader:958:12)
    at Module.require (node:internal/modules/cjs/loader:1141:19)
    at require (node:internal/modules/cjs/helpers:110:18)
    at Object.<anonymous> (C:\nvm\v18.15.0\node_modules\npm\lib\npm.js:1:18)
    at Module._compile (node:internal/modules/cjs/loader:1254:14)

ERROR: npm v9.5.0 is known not to run on Node.js v18.15.0. You'll need to upgrade
to a newer Node.js version in order to use this version of npm. This version of
npm supports the following node versions: `^14.17.0 || ^16.13.0 || >=18.0.0`. You
can find the latest version at https://nodejs.org/.

ERROR:
C:\nvm\v18.15.0\node_modules\npm\node_modules\@npmcli\arborist:1
../../workspaces/arborist
^

SyntaxError: Unexpected token '.'
    at internalCompileFunction (node:internal/vm:73:18)
    at wrapSafe (node:internal/modules/cjs/loader:1176:20)
    at Module._compile (node:internal/modules/cjs/loader:1218:27)
    at Module._extensions..js (node:internal/modules/cjs/loader:1308:10)
    at Module.load (node:internal/modules/cjs/loader:1117:32)
    at Module._load (node:internal/modules/cjs/loader:958:12)
    at Module.require (node:internal/modules/cjs/loader:1141:19)
    at require (node:internal/modules/cjs/helpers:110:18)
    at Object.<anonymous> (C:\nvm\v18.15.0\node_modules\npm\lib\npm.js:1:18)
    at Module._compile (node:internal/modules/cjs/loader:1254:14)`enter code here`

Solution

  • Same issue for me, I was trying to install angular as well, and it was caused by nvm-windows sort of explained here. Even the latest version of nvm-windows (1.1.10) and reinstalling node versions did not resolve this issue for me. I found a script that fixed the links and resolved the issue in node v19.8.1 here:

    You save the script anywhere as yourfile.js, run as admin node yourfile.js and it will fix the broken links in Roaming\nvm\<node version>\node_modules\npm\node_modules.

    If you want to fix it for multiple node versions, switch using nvm and run the script again.