Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot update version of node - unexpected token

Downgraded my node recently for a tech assessment to vers 12, now wanted to upgrade but seems something is wrong. Ive tried a heap of things that everyone suggests.

Not a very proficient mac user, so any help appreciated

MacBook-Pro ~ % npm install -g n
ERROR: npm v9.1.2 is known not to run on Node.js v12.22.12. 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:
/usr/local/lib/node_modules/npm/lib/utils/exit-handler.js:22
  const hasLoadedNpm = npm?.config.loaded
                           ^

SyntaxError: Unexpected token '.'
    at wrapSafe (internal/modules/cjs/loader.js:915:16)
    at Module._compile (internal/modules/cjs/loader.js:963:27)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
    at Module.load (internal/modules/cjs/loader.js:863:32)
    at Function.Module._load (internal/modules/cjs/loader.js:708:14)
    at Module.require (internal/modules/cjs/loader.js:887:19)
    at require (internal/modules/cjs/helpers.js:74:18)
    at module.exports (/usr/local/lib/node_modules/npm/lib/cli.js:76:23)
    at Object.<anonymous> (/usr/local/lib/node_modules/npm/bin/npm-cli.js:2:25)
    at Module._compile (internal/modules/cjs/loader.js:999:30)

-MacBook-Pro ~ % node -v
v12.22.12

Tried npm install -g n

like image 924
stevo Avatar asked Jun 16 '26 21:06

stevo


2 Answers

Try using the OSX installer on nodejs.org/. It will update your local node installation and also a compatible npm version (v8.19.2 as of writing). Then the error should be gone when typing node -v.

like image 153
Daan_z Avatar answered Jun 18 '26 11:06

Daan_z


ERROR:
/usr/local/lib/node_modules/npm/lib/utils/exit-handler.js:22
  const hasLoadedNpm = npm?.config.loaded
                           ^
SyntaxError: Unexpected token '.'

To resolve these issues, you have to delete node and npm from your system and reinstall both of them. then you can resolve this issues.

  1. First of all install Homebrew
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
  1. Type the following command to install Node.js and NPM:
  2. brew install node
  3. To check node version: node -v
  4. To check npm version: npm -v
like image 22
Firoz khan Avatar answered Jun 18 '26 10:06

Firoz khan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!