Solution to the inconsistency of node versions in different projects

Solution to the inconsistency of node versions in different projects

1. No need for nvm

first step

First go to the nodejs official website to download different versions of node (official website address: https://nodejs.org/en/download/releases ).
To download two different versions, download the .zip file and unzip it directly to use.
Insert image description hereInsert image description here

Step 2

Unzip the two different versions of the files under C:\Program Files\nodejs (my two versions are inconsistent with the above picture)
Insert image description hereand then create the node_cache and node_global folders under each version (remember to give full control permissions)
Insert image description here

Grant permissions: Properties>Security>Edit>Full Control
Insert image description hereThen we go to the C:\Users\username under the C drive and there is a .npmrc file (it should be this file only after global installation (i.e. mis file installation), I did not delete it after uninstalling it before. If not, you can install the mis file first, and then do not delete the files in the C:\Users\16786 directory after uninstalling)). After opening it, replace the prefix and cache in npmrc with what you need at this time. node_cache and node_global under the node version.
(node14.21.3 is the node path of the version we currently need. When we need to replace other versions of the project, replace it with the corresponding version installation directory (that is, our decompression path))

npmrc file content

prefix=C:\Program Files\nodejs\node14.21.3\node_global
cache=C:\Program Files\nodejs\node14.21.3\node_global
registry=https://registry.npm.taobao.org/

Then configure user variables and system variables

	此电脑(右键属性)》高级系统设置》

Edit user variables
Edit user variable path and add C:\Program Files\nodejs\node14.21.3\node_modules
(node14.21.3 is the node path of the version we currently need. When we need to replace other versions of the project, replace it with the corresponding one.
Insert image description here
Edit the system variable in the version installation directory (that is, our decompression path)
1. Add the system variable NODE_PATH, the value is C:\Program Files\nodejs\node14.21.3\node_modules
(node14.21.3 is the node path of the version we currently need , when we need to replace other versions of the project, replace it with the corresponding version installation directory (that is, our decompression path))

Insert image description here
2. Edit the system variable path, add %NODE_PATH% and C:\Program Files\nodejs\node14.21.3
(node14.21.3 is the node path of the version we currently need. When we need to replace other versions of the project, replace it with the corresponding version installation directory (that is, our decompression path))
Insert image description here

After that we can use npm to install project dependencies and package the project,
npm install
npm run serve

Note: When changing to different versions, just change all the above file directories.

2.Use nvm

See the blog https://www.cnblogs.com/love920526/p/16741521.html

Guess you like

Origin blog.csdn.net/qq_43767886/article/details/130198239