'Visual Studio Code (Windows) Not Detecting Global NPM Modules

I'm experiencing an issue where Visual Studio Code in Windows 10 is not able to detect globally installed NPM packages within the Integrated Terminal.

For example, if the windows command prompt I install @angular/cli via command npm install -g @angular/cli, within that command prompt I can execute @angular/cli commands such as ng --version without error. After that global npm module install, within Visual Studio Code, performing the same ng --version gives me the error:

The term 'ng' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

I can however within the integrated terminal successfully perform commands such as npm -v and node -v.

I have the following items in my system environment variables

C:\Program Files\nodejs\

%AppData%\npm

Are there Visual Studio Code user or system environment variables I'm missing to allow detection of global npm modules?

Thank you for any help you can provide.



Solution 1:[1]

Visual Studio Code must be "Run as Administrator" for working Terminal Commands.

Solution 2:[2]

no need to do anything else just follow below steps -

  1. right click on my computer (this pc).
  2. go to properties.
  3. click on advanced system setting.
  4. click on environmental variable.
  5. select path variable from system variable.
  6. click on edit button.
  7. add %AppData%\npm and %ProgramFiles%\nodejs\ at top of the list. 8 click on ok. ok. ok
  8. restart your system.
  9. after restart open visual studio code as run as administrative mode.
  10. Enjoy...............!!!!!

enter image description here

Solution 3:[3]

Run Visual studio code as an administrator. Then type ng command. It should work

Solution 4:[4]

You can resolve the issue by opening the VS Code Terminal and type

npm install -g @angular/cli

This should resolve the issue.

Solution 5:[5]

Reboot your computer , this worked for me

Solution 6:[6]

  1. Run powershell or cmd prompt in admin mode.
  2. Check if npm and node commands work (if not, then check environment variables as others have mentioned).
  3. Update node using npm [https://stackoverflow.com/questions/18412129/how-can-i-update- npm-on-windows]
    • Set-ExecutionPolicy Unrestricted -Scope CurrentUser -Force
    • npm install -g npm-windows-upgrade
    • npm-windows-upgrade
  4. Run npm install -g @angular/cli
  5. Run ng --version in Visual Studio Code to see if it's now working.

Solution 7:[7]

If you have entered the environment variable and it is still not recognized and if you don't want to reboot your computer because you have so many things running then just reboot your Visual Studio Or Visual Studio Code and then Open Terminal (ctrl + `) and run

npm install

Now it will work fine.

Solution 8:[8]

If you do not have access to Environmental variable (office machines).

You can try to run command like this:

npm run <your angular command>

it works as well, just need to add npm run before ng command

Example -> npm run ng g c shop/cart

enter image description here

Solution 9:[9]

I found that adding %AppData%\npm to your Path variable made it work for PowerShell and the Command Prompt, it still did not work for the integrated PowerShell in VS Code for me.

When I changed it from %AppData%\npm to the actual path C:\Users\<USER>\AppData\Roaming\npm where <USER> is your user directory, and reopened VS Code it started working.

Solution 10:[10]

To me the solution was adding the extensions for npm: enter image description here