The latest version of nodejs and npm version mismatch problem is solved: ERROR: npm v9.5.1 is known not to run on Node.js

Recently, the project uses node and npm. Check the current version and find that there is an error

node -v

npm -v

 

ERROR: npm v9.6.2 is known not to run on Node.js v12.13.1. 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/.

After searching in multiple directions, I found the version comparison chart of node and npm

Previous Versions | Node.js

1. I thought that npm reported an error, just downgrade the npm version to a lower version, but the result is still an error

npm -g install [email protected]

2. Brew installation and upgrade to the new version of node, replacing the current low version, the result did not work

brew install node@16

3. Finalize the idea, because node did not report an error, but npm reported an error, so you need to switch the node version, (you need to catch the node version management tool nvm)

install nvm

brew install nvm

 Check nvm version

nvm --version

Explain the first step in detail

nvm --version

 //problem appear. To configure
 zsh: command not found: nvm

Step 2: nvm configuration
1.vim ~/.bash_profile

Click i to insert the following configuration

export NVM_DIR=~/.nvm
source $(brew --prefix nvm)/nvm.sh

After inserting, click Esc and use: wq. to save and exit

Execution: source ~/.bash_profile If there is a problem, ignore it and go on

2.vim ~/.zshrc

Click i to insert the following configuration

export NVM_DIR=~/.nvm
source $(brew --prefix nvm)/nvm.sh

After inserting, click Esc and use: wq. Save and exit
Execute: source ~/.zshrc

3.vim ~/.profile

Click i to insert the following configuration

export NVM_DIR=~/.nvm
source $(brew --prefix nvm)/nvm.sh

After inserting, click Esc and use: wq. Save and exit
Execute: source ~/.profile

Finally, start testing
Execution: nvm --version
shows the version number, indicating that the configuration is successful: 0.39.3

4. Install the specified version of node through nvm

Due to the prompt, the version starting from 14 or 16 or 18 must be

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/.

 We will install the 16.13.0 version of node through nvm


nvm install 16.13.0

 

Finally check the results

 

The node version has been upgraded, npm no longer reports an error, and the upgrade is complete

 

 

Guess you like

Origin blog.csdn.net/qq_33665793/article/details/129918730