why

  • nvm-windows
  • NVM Image source Settings
  • Pits in NVM usage
  • NVM is installed successfully, Node is installed successfully and can work, but NPM is using an error

Applicable scenario

Inherited old code, Node version is too high to run successfully. Or you may need to use more than one version of Node.

The environment

windows 10 64bit

Refer to the blog

Lewis — Uninstall Node.js completely and install node.js multi-version management tool nVM-Windows on Windows

– The NPM command did not find a solution after NVM installed Node on Windows

background

Do not note the environment and version of the tutorial are playing rogue, in the beginning of a new technology or a new framework, we often go to search others hellow World tutorial, but very gas is, in any case, according to the steps are not successful, in this kind of pit I encountered, the basic is the environment and version of the different caused….. (except Internet related)

For example, I recently read a senior’s ethereum tutorial, and I’m still working on a two-year-old Angular project. This article is a precursor to the next article on Ethereum, because that tutorial requires an older version of Node.

Train of thought

  1. Uninstall the node
  2. Delete paths and residual files
  3. NVM – Windows installation
  4. Configuring a Mirror Source

steps

  1. Unmount an existing node on your system (if any)

    Here based on Windows NVM node installation after the NPM command can not find a solution to the problem, simplified and improved on this basis.

    • Uninstall Node in the uninstall program
    • Remove all paths associated with Node from environment variables (both user and System level)
    • Delete files in the following paths (some files may exist only)

      C:\Program Files (x86)\nodejs C:\Program Files\nodejs C:\Users{User}\AppData\Roaming\npm C:\Users{User}\AppData\Roaming\ NPM -Cache C:\Users{User}\node_modules

  2. Download the latest version of NVM and install nVM-setup.zip
  3. Replace the mirror source inPath C: \ Users \ {User} \ AppData \ Roaming \ NVM \ Settings. TXTAdd the following two items
node_mirror: https://npm.taobao.org/mirrors/node/
npm_mirror: https://npm.taobao.org/mirrors/npm/
Copy the code

NVM installation path C: Users\i353667\AppData\Roaming\ NVM folder folder C: Users\i353667\AppData\Roaming\ NVM Folder Folder folder

  1. The use of NVM
# get available node version list
    nvm list available
# install specific node version you need
    nvm install The_Version_You_Need
# list the node you have installed in your PC
    nvm list
# switch node version you need 
    nvm use The_Version_You_Need
Copy the code

Error handling

Most common solutions to NVM errors on Windows are searchable, but there is one particular one that I didn’t find listed here.

  • NVM install specifies the version of node, and after the switch, using the node command normal, such as node –version, but using the NPM command will error, and the error will vary according to the node version, but fundamentally NPM can not find. If you open C:\Users\{User}\AppData\Roaming\ NVM \v9.11.1\node_modules and find no NPM folder, that is the problem.

  • Solution Uninstall the current version and reinstall it. Sometimes I have to repeat twice before I succeed, and the sign of success is that the NPM folder appears in the node_modules folder, or that the command line calls NPM with no error.

For more original Haytham articles, please follow the public account xu Julong: