Home  >  Article  >  Web Front-end  >  What should I do if node.js npm cannot be used?

What should I do if node.js npm cannot be used?

藏色散人
藏色散人Original
2021-12-10 11:11:219266browse

Node.js npm cannot be used Solution: 1. Uninstall node.js; 2. Delete npm and npm-cache under "C:\Users\Administrator\AppData\Roaming"; 3. Reinstall Node.js is enough.

What should I do if node.js npm cannot be used?

The operating environment of this article: Windows 7 system, nodejs version 8.9.3, Dell G3 computer.

What should I do if node.js npm cannot be used?

About the solution to the inability to use npm after nodejs is installed:

Because it is required to use vue in conjunction with node for project development environment deployment, try to install nodejs.

As for what others said after installing version 6, it will be stable. In fact, after installing version 6, you can use global npm.

Node.js installation package and source code download address is: https ://nodejs.org/en/download/.



##Select this Enter all the way

##Click to agree and it will be installed to the C drive by default


After installation, click the [Finish] button to complete the installation

At this point, Node.js has been installed. You can perform a simple test first to see if the installation is successful. There will be more details later. To configure the environment

Press the [win R] key on the keyboard, enter cmd, and then press Enter to open the cmd window

This window does not have administrator rights at this time

This is an important point!!!!


## This is the normal installation effect if the C drive has not been touched before

Otherwise this will happen

ERR error This means the path is wrong The npm package under that folder cannot be found.

At this time, check if you have used npm before. If so, delete and reinstall

Delete cleanly

After installation Click the [Finish] button to complete the installation

Now Node.js has been installed. You can first briefly test whether the installation is successful, and then configure the environment.

Press [win R] on the keyboard Key, enter cmd, then press Enter to open the cmd window

node -v is normal, npm -v reports an error

As shown below:

What should I do if node.js npm cannot be used?
Error: Cannot find module 'internal/fs'…

The solution is as follows:

1. Uninstall node.js, specific operations:
What should I do if node.js npm cannot be used?

2. Delete npm under C:\Users\Administrator\AppData\Roaming , The specific operation of npm-cache is as follows:
What should I do if node.js npm cannot be used?

3. Reinstall node.js, and enter node -v and npm -v in dos again. You can see the corresponding version number as shown in the text. Shown in a picture.

Follow the steps to install once. The command to open this time must be window x

Select the command prompt (Administrator A) and click to operate

Then check node -v to view the version npm -v to view the version It will return to normal

After installation, click the [Finish] button to complete the installation

At this point, Node.js has been installed. You can first simply test whether the installation is successful, and then configure the environment.
Press the [win R] key on the keyboard, enter cmd, and then press Enter. Open the cmd window

Here is a description: The new version of Node.js has its own npm, which will be installed together when installing Node.js. The role of npm is to manage the packages that Node.js depends on, which is also understandable. What you need to install/uninstall Node.js

5. Environment Configuration

Description: The environment configuration here mainly configures the path where the global module installed by npm is located, and the path of the cache. The reason for configuring it is because it will be executed similarly in the future: When using the installation statement of npm install express [-g] (the following optional parameter -g, g represents global installation), the installed module will be installed to [C:\Users\username\AppData\Roaming\npm 】path, occupying C drive space.
For example: I want to put the path of the full module and the cache path in the folder where I installed node.js, then create two folders [node_global] under the folder I installed [D:\Develop\nodejs] ] and [node_cache] as shown below:

After creating two empty folders, open the cmd command window, enter

npm config set prefix "D:\Develop\nodejs\node_global"
npm config set cache "D:\Develop\nodejs\node_cache"

, then set the environment variables, close the cmd window, "My Computer "-Right click-"Properties"-"Advanced System Settings"-"Advanced"-"Environment Variables"

Enter the environment variables dialog box, create a new [NODE_PATH] under [System Variables], enter [D:\ Develop\nodejs\node_global\node_modules], change [Path] under [User Variables] to [D:\Develop\nodejs\node_global]

6. Test

After configuration, After installing a module for testing, we will install the most commonly used express module, open the cmd window,
Enter the following command to install the module globally:

npm install express -g     # -g是全局安装的意思

Add Taobao image

After installation, click the [Finish] button to complete the installation.

At this point, Node.js has been installed. You can first perform a simple test to see if the installation is successful, and then configure the environment.
On the keyboard Press the [win R] key, enter cmd, then press Enter to open the cmd window

How to use mirroring (any of the three methods can solve the problem, it is recommended to use the third method, hard-code the configuration, The configuration will still be there when you use it next time):

1. Pass the config command

npm config set registry https://registry.npm.taobao.org  npm info underscore (如果上面配置正确这个命令会有字符串response)

2. Specify

npm --registry https://registry.npm.taobao.org info underscore

3 on the command line. Edit ~/.npmrc Add the following content

registry = https://registry.npm.taobao.org

安装完后点击【Finish】按钮完成安装

至此Node.js已经安装完成,可以先进行下简单的测试安装是否成功了,后面还要进行环境配置
在键盘按下【win+R】键,输入cmd,然后回车,打开cmd窗口

推荐学习:《node.js视频教程

The above is the detailed content of What should I do if node.js npm cannot be used?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn