node, npm, pnpm download, install, uninstall, and step into pitfalls

1. Node download and installation tutorial

(1) node download official website: Download | Node.js Chinese website (nodejs.cn)
(2) node Chinese documentation: API documentation | Node.js Chinese website (nodejs.cn)

1. Select the corresponding installation package to install, or click the windows installation package directly to download.

2. Double-click the installation package to install.

Check it after the download is complete, and then pay attention to the directory where nodejs is located.

After the installation is completed, run cmd as administrator and the node and npm version numbers will be displayed, indicating that the installation was successful

3. Configure npm’s path when installing global modules and the cache path

(1) The module is usually installed in npm and npm_cache under the C:\Users\username\AppData\Roaming path by default, which is inconvenient to manage and takes up space on the C drive.
(2) Configure a customized global module installation directory here, create two new folders node_global and node_cache in the node.js installation directory, and then execute the following two commands under the cmd command: (For the path, see the nodejs installation path, which I installed The root path is: D:\
odejs)

npm config set prefix "D:\
odejs\
ode_global"
npm config set cache "D:\
odejs\
ode_cache"

(3) After successful execution, then go to this computer -> Right-click Properties -> Advanced System Settings -> Environment Variables -> System Variables to create a new variable named “NODE_PATH” with a value of “D:\
odejs\
ode_modules”, as follows picture:

(4) Finally edit the Path in the user variable and change “C:\Users\username\AppData\Roaming\
pm” to “D:\
odejs\
ode_global” (if not, just add one directly)

4. Configure npm domestic Taobao image
D:\
odejs\
ode_modules
5. Specific steps:

(1) Install @vue/cli globally (first use)

npm install -g @vue/cli

(2) After the installation is completed, restart cmd, enter vue, and the following figure will be returned to indicate that the installation is successful.

(3) Finally, switch to the directory you need and use the command to create the project

vue create project name

The installation is basically completed

2. Configure npm, yarn, pnpm

1. Configure npm (you need to create new directories yourself)

npm help npm or npm help install # Open the local npm document (or npm install document)
npm [command] -h # Show command usage
npm -l # Show all command usage
npm adduser # Log in or register
Start here————-
npm config ls -l # Query all npm related configurations and call npm config set to change or overwrite
npm config set prefix “D:\
odejs\
pm-global-modules” # Configure npm global installation path, add Path %NODE%\
pm-global-modules’
npm config set cache “D:\
odejs\
pm-cache” # Configure npm cache path
npm config set registry “https://registry.npm.taobao.org/” # Modify the npm image (https://registry.npmjs.org/) (you can modify the cnpm image after installing cnpm)
After the configuration is successful, call npm config ls again to view

2. Install yarn

npm install -g yarn # Install yarn globally, execute yarn help and yarn help [command] to learn how to use it
yarn –version # Detect yarn installation version 1.22.x, execute yarn set version berry before using yarn init, the version will become 2.x.x in this folder
yarn config list # View yarn related configurations
yarn global bin # yarn global bin location
yarn global dir # yarn global installation location
yarn cache dir # yarn global cache location
yarn config set prefix “D:\
odejs\Yarn\Data\global” # Configure yarn global bin path (D:\
odejs\Yarn\Data\global\bin) Add Path ‘%NODE%\Yarn\Data\global\bin ‘
yarn config set global-folder “D:\
odejs\Yarn\Data\global” # Configure yarn global installation path
yarn config set link-folder “D:\
odejs\Yarn\Data\link” # Configure yarn global link path
yarn config set cache-folder “D:\
odejs\Yarn\Cache” # Configure yarn global cache path
yarn config set registry “https://registry.npm.taobao.org/” # Modify yarn image (https://registry.yarnpkg.com)

3. Install pnpm

npm install -g pnpm # Install pnpm globally
pnpm –version # pnpm version
pnpm config set store-dir “D:.pnpm-store” # pnpm global warehouse path (similar to .git warehouse)
pnpm config set global-dir “D:\
odejs\pnpm\pnpm-global” # pnpm global installation path
pnpm config set global-bin-dir “D:\
odejs” # pnpm global bin path
pnpm config set state-dir “D:\
odejs\pnpm” # pnpm creates the directory where the pnpm-state.json file is created
pnpm config set cache-dir “D:\
odejs\pnpm\cache” # pnpm global cache path

3. Uninstall node

1. Find the uninstall package corresponding to node and uninstall it.

2. If not, uninstall nodejs in the control panel program.
3. Delete these two folders

4. Check if there is the following folder, if it exists, delete it
c://user/xxx/node_models
c://ProgramFiels/nodejs
c://user/xxx/AppData/Roaming/npm
c://user/xxx/AppData/Roaming/npm-cache

4. Error when installing node: vue is not an internal or external command, nor is it an operable program or batch file method

1. Reconstruction project
npm install chromedriver --chromedriver_cdnurl=http://cdn.npm.taobao.org/dist/chromedriver

After completing the operation, recreate the project.

2. Clear cache
npm cache clean --force

Clear npm’s cache (if it doesn’t work, it proves that it is not a cache problem, it is basically invalid)

3. Reinstall Taobao source

If Taobao image is selected during installation and the above two steps still do not work -> Reinstall the following Taobao source

npm install -g cnpm --registry=https://registry.npm.taobao.org
4. Modify useTaobaoRegistry

Some people say that changing “useTaobaoRegistry” in C:\Users*****.vuerc: true to false can solve this problem. After testing, it was found that it still doesn’t work (* is the computer name)

5. Reinstall node
6. Delete npmrc file

Delete the .npmrc file under the fourth point file and reinstall the Taobao image.

npm install -g cnpm --registry=https://registry.npm.taobao.org

Re-create the project after installation is complete:

vue create test

finally! ! ! Created successfully! ! !

7. Node version problem

Check the information, it may also be a node version issue. The node 15.13.0 I used at the beginning had this problem, and then I just switched back to the original node 14.15.0 (you can troubleshoot according to your own situation)

8. Run as administrator

When creating a project, you need to run it as an administrator!

5. Error when installing/running pnpm

1. When running pnpm -v, the error reported is not an internal or external command, nor is it an operable program, and there are no pnpm related files.

You need to uninstall node and npm and reinstall them.

2. When running pnpm -i / pnpm -v, the error message is not an internal or external command, nor is it an operable program. But the pnpm.cmd file exists.

The pnpm system variable needs to be configured.
(1) Find the location of pnpm.cmd and copy the file location.

(2) Go to Environment Variables => System Variables => PATH and add the pnpm file path, and that’s it.

3. When running pnpm -i, the error pnpm is reported: The file D:\Git\
ode_global\pnpm.ps1 cannot be loaded because running scripts is prohibited on this system.

  1. Enter Windows PowerShell in the search box on the start interface and click Run as administrator:
  2. Enter set-ExecutionPolicy RemoteSigned, then select Y when the option appears
  3. Finally, you can use pnpm to run the system.

This method can be used for commands such as yarn, provided that these commands are installed globally.