VS Code reports an error: The "xxx" item cannot be recognized as the name of a cmdlet, function, script file, or executable program.

Note: There are many possible reasons for the same error, and this answer is mainly aimed at the wrong setting of Nodejs environment variables!

This error has several notable features:

1. It is completely possible to install the package in the VS Code terminal, but after the installation is complete, an error will be reported when entering the command. For example, after installing nodemon and yarn, the input command nodemon -v and yarn -v will both report an error.

 2. After installing nodemon and yarn, enter the command nodemon -v and yarn -v in cmd and both report an error: "xxxx is not an internal or external command, nor is it an operable program or batch file".

3. If you have modified the global module download path, you will find that all the packages are installed to the path in the c drive in the figure below, but not to the modified path of the D drive.

Then the problem you encounter is probably that the Nodejs environment variable is set incorrectly, just modify or add the environment variable.

 Modify environment variables: Right-click on this computer , slide to the bottom in About , open advanced system settings , and open environment variables, as shown in the figure below

Shown:

(1): Modify the user variable first: Change the Path of the user variable to the global module download path you set yourself . For example , the global module download path I set is: D:\NodeJS\node_global, do not copy my path, be sure to Follow the path you set!

 (2) Create a new environment variable under the Path of the system variable : D:\NodeJS\node_global

 

(3), Create a new system variable  NODE_PATH: D:\NodeJS\node_global\node_modules

Note: This path has more node_modules than the previous one. If there is no folder in the computer, create a folder first.

 Enter the commands nodemon -v and yarn -v in the VS Code terminal and cmd, and no error is reported.

 

 

 

 

 

 

Guess you like

Origin blog.csdn.net/Hi_one_two_three/article/details/129223813