Issue
I'm having trouble figuring out why npm is not working correctly. I'm on ubuntu 22.04.2LTS.
I don't remember what I did to install node.js the first time, but I remember I installed Angular cli through npm install -g @angular/cli
I tried using ng version
to check my angular installation, but this appears:
Node.js version v12.22.9 detected.
The Angular CLI requires a minimum Node.js version of v18.13.
Please update your Node.js version or visit https://nodejs.org/ for additional instructions.
Whenever I try to use npm -v
to check my node.js installation, this appears instead:
ERROR: npm v10.2.3 is known not to run on Node.js v12.22.9. This version of npm supports the following node versions: `^18.17.0 || >=20.5.0`. You can find the latest version at https://nodejs.org/.
ERROR:
/usr/lib/node_modules/npm/lib/utils/exit-handler.js:19
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/lib/node_modules/npm/lib/cli-entry.js:15:23)
at module.exports (/usr/lib/node_modules/npm/lib/es6/validate-engines.js:39:10)
at module.exports (/usr/lib/node_modules/npm/lib/cli.js:4:31)
At this point I tried doing sudo snap install node --classic --channel=20
but this didn't change anything.
I tried: sudo npm uninstall -g npm
but always get the same ERROR as above.
I wanted to delete manually the folder on /usr/lib/node_modules, I don't know if it will help and then reinstall node.js?
Solution
You need to update the node version globally either you can update your node version with the lates one or you can use it nvm to to use the latest node version or keep switching whenever you required.
Solution 1-
To update you node version with the latest one
Solution 2-
Using nvm - to install you need to follow this URL https://www.freecodecamp.org/news/node-version-manager-nvm-install-guide/
Once you installed the nvm you need to follow these two steps if you face any issue.
nvm install 18
nvm use 18
Solution 3-
Using volta - https://volta.sh/
# install Volta
curl https://get.volta.sh | bash
# install Node
volta install node
# then pin the node version in your current repository using this command
vola pin node@18
Note- Make sure you stay on your current project directory when you perform these task.
Happy Coding - Cheers 🥂
Answered By - Rの卄IT
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.