[Front-end exception] vscode: Cannot identify the "cnpm" item as the name of a cmdlet, function, script file or executable program, Cannot find module "webpack"

Contents of this article

1. Project background

Second, the error message

Three, the solution

Step 1: Check whether the cnpm package management tool is installed locally

Step 2: Enter the cnpm -v command to check

Check successful

Check failed


1. Project background

Compiler: VScode + Vue project.

VSCode reported an error when opening the front-end vue project.

Second, the error message

The following is the error message displayed on the VScode project console:

PS D:\work-span\project> cnpm install webpack-dev-server -g
cnpm : 无法将“cnpm”项识别为 cmdlet、函数、脚本文件或可运行程序的名称。请检查名称的拼写
,如果包括路径,请确保路径正确,然后再试一次。
所在位置 行: 字符:
+ cnpm install webpack-dev-server -g
+ ~~~~
+ CategoryInfo : ObjectNotFound: (cnpm:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException

Three, the solution

Step 1: Check whether the cnpm package management tool is installed locally

Command: npm list --depth=0 -global  Check whether cnpm is installed on the computer

If it has been installed, then there will be content as shown in the figure below:

If it is not installed, you need to install the mirror. The execution command is: npm install -g cnpm --registry=https://registry.npm.taobao.org

The installation process may take several minutes~~~~

After the installation is successful, there will be something similar to the following:

Step 2: Enter the cnpm -v command to check

Check successful

1. If the content shown in the figure below appears, you can proceed

Check failed

2. If the error shown in the blog title still appears, it is most likely caused by your local environment variable configuration (that is, the path of cnpm is not recognized)

Need to configure system environment variables: Computer-->Properties-->Advanced System Configuration-->Environment Variables-->System Variables-->PATH Add at the end (my path is F:\Develop\nodejs\node_global), according to You actually modify this path.

Then restart cmd and enter cnpm -v to test. If successful, proceed to your next step.

 

note:

If it still reports an error, please restart your computer. Restarting can solve 90% of the problems.

 

 

end!

Guess you like

Origin blog.csdn.net/weixin_44299027/article/details/106955854