Nvm manages the node version and the version of npm corresponding to node

        I came back from the May Day holiday and turned on the computer and found that my vscode could not successfully run the project. After npm run dev, there was no response, so I thought about using cmd to open it and try it. After the cmd was opened, there was only a horizontal cursor flashing on the screen, and it automatically closed after a few seconds. I read the solutions written by other bloggers and tried them one by one. Either it is the file (auto run) that is not mentioned in the folder, or the environment variable is also ok, and there are other methods that have not been solved. There is no way to reinstall the system (win10). After reinstalling the system, cmd can be opened normally, and the project can also run, but the version of node is too high, which does not match the version of npm, and an error will be reported when running. The error is as shown in the figure below:

At present, my node version is v18.16.0, and the npm version is 9.5.1 (check the npm version: open cmd, enter npm -v) 

1. Query the version of node.js corresponding to npm, document address: previous version | Node.js

2. After confirming the node.js version, download nvm: 

  • nvm-setup.zip : This is an installation package, click to install after downloading, it can be used without configuration.

3. Install nvm:

①Double-click nvm-setup.exe, choose to agree to the agreement in the pop-up interface, and then next

②Come to the interface of setting the installation directory of nvm, change the installation path, and then next

 ③ After selecting the path to install node, click next

④Click install and select Yes

 At this point, nvm is installed, and the system will help us configure the path of nvm in the environment variable (meaning that the nvm command can be used in any directory on the computer)

 In the blank space of any directory, hold down shift, right-click and select "Open Powershell window (S) here", enter relevant commands in the pop-up command window, and view the nvm version number, nodejs version list, nvm command description, etc.: as shown below

 4. Configure the mirror address of node and npm:

        In the nvm installation directory, find the setting.txt file and add the following two lines:

node_mirror: https://npm.taobao.org/mirrors/node/
npm_mirror: https://npm.taobao.org/mirrors/npm/

5. Use mvm to install other versions of nodeJs

Open poweshell, and install other lower versions of nodeJs as shown in the figure below

 As shown in the figure above, the two versions of nodejs are installed and switched to the lower version

Guess you like

Origin blog.csdn.net/Stitch_xiao/article/details/130491453