Message "the term 'ng' is not recognized as the name of a cmdlet"

node.jsAngularPowershellNpmAngular Cli

node.js Problem Overview


Today, while working through some basic AngularJS introduction, I ran into a problem.

I opened PowerShell to get going on the project. NPM worked.

I was able to install Angular using:

npm install -g @angular/cli

Anytime I tried to run ng, I would get:

> the term 'ng' is not recognized as the name of a cmdlet

node.js Solutions


Solution 1 - node.js

The first path in the path variable needs to be the NPM path. Opening the Node.js command prompt I found that the ng command worked there. I dug into the shortcut and found that it references a command to ensure the first Path variable is NPM. To Fix:

  1. Right Clicked on My Computer (windows)
  2. Selected Advanced System Settings
  3. Clicked "Environment Variables"
  4. Under "Path" variable, made the FIRST value listed %AppData%\npm

Once I did that I was able to close powershell and reopen and all worked.

Solution 2 - node.js

First set up Node.js, and then run this command to install Angular globally:

npm install -g @angular/cli

Now run the ng command. This worked for me.

Solution 3 - node.js

I used the following:

npm run ng serve

It worked for me without need to set environment variables.

I had to install the TypeScript package after it:

npm install typescript@">=3.4 <3.6"

Solution 4 - node.js

In the "Environment Variables"

In the "System variables" section

In the "Path" variable and before "C:\Program Files (x86)\nodejs\" add => "%AppData%\npm"

Solution 5 - node.js

This solution worked for me:

Add a path to your environment Variable

C:\Users\YourPcName\AppData\Roaming\npm

As well as your bin folder of the Angular file (present their itself):

C:\Users\YoutPcName\AppData\Roaming\npm\node_modules\angular-cli\bin

And then run

ng -v

It will pop up the Angular CLI GUI in your Command prompt.

Note after running npm i -g @angular/cli, do restart your command prompt and check if it works. Otherwise, clean the cache and repeat the above steps.

Solution 6 - node.js

Changing the policy to Unrestricted worked for me:

Set-ExecutionPolicy Unrestricted -Scope CurrentUser

Solution 7 - node.js

Installing Angular CLI globally solved my problem.

npm install -g @angular/cli

Solution 8 - node.js

I was getting this error in Visual Studio Code while doing ng-build. Running the below command in cmd fixed my issue:

npm install -g @angular/cli@latest

Solution 9 - node.js

If you do not have access to environment variables (e.g., office machines), you can try to run a command like this:

npm run <your Angular command>

It works as well. You just need to add npm run before ng command.

Example:

npm run ng g c shop/cart

Enter image description here

Solution 10 - node.js

For the Visual Studio Code Terminal

First open cmd and install angular-cli as global

npm install -g @angular/cli

Then update your environment variables following these steps:

  1. Win + S. This will open a search box
  2. Type Edit Environment Variables
  3. Open Environment Variables
  4. Add %AppData%\npm inside PATH
  5. Click OK and Close.

Now you can restart your Visual Studio Code and it will work as it will normally do.

Solution 11 - node.js

If your project name contains '-', remove it and try.

This can cause problems in running 'ng'.

Solution 12 - node.js

Open Edit the system environment variables.

In the "Path" and "PS Module Path" variable, add "%AppData%\npm"

Run Visual Studio Code as Administrator.

It works for me!

Solution 13 - node.js

You just need to close Visual Studio Code and restart again. But to get the ng command to work in Visual Studio Code, you need to first compile the project with cmd in administrator mode.

I was also facing the same problem. But this method resolved it.

Solution 14 - node.js

  1. I right-clicked on My Computer (Windows)
  2. Selected Advanced System Settings
  3. Clicked "Environment Variables"
  4. Under "Path" variable, made the first value listed %AppData%\npm

Initially:

C:\Program Files\Microsoft MPI\Bin;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0;C:\Program Files\TortoiseSVN\bin;

After path adding:

C:\Program Files\Microsoft MPI\Bin;%AppData%\npm;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0;C:\Program Files\TortoiseSVN\bin;

One more thing you can try, if the error is still coming, as below

  1. Go to project location via command prompt:C:\Users\brijeshray\ParentChild>

  2. Reinstall or update existing angular as:

     npm install -g@angular/cli@latest
    
  3. Go to computer or PC → PropertiesAdvanced system settingEnvironment Variable → add a path below "User variable" (if 'Path' not there) → C:\Users\brijeshray\AppData\Roaming\npm → save it and restart Visual Studio Code

    Enter image description here

Solution 15 - node.js

Fix: Running scripts is disabled on this system

Open PowerShell

Set-ExecutionPolicy RemoteSigned
A

(A: YES TO ALL)

Done!

Solution 16 - node.js

All answers are about how to fix it, but the best is to download Node.js and let the installer add to PATH variable.

Version 12 and 13 are too new, so I had to download 11.15.

Solution 17 - node.js

Selected Advanced System Settings

Enter image description here

Clicked "Environment Variables"

Enter image description here

Under "Path" variable, made the first value listed to be %AppData%\npm

Enter image description here

I did that. Close PowerShell and reopen. All worked.

Solution 18 - node.js

Instead of using the "ng serve" command in the Visual Studio code terminal, open the Angular app path in the command prompt (Run as Administrator).

Then issue "ng serve" command.

Then open a browser and go to the http://localhost:4200/.

It works for me.

Solution 19 - node.js

You should update Node.js to the latest version. Otherwise uninstall Node.js and install it again.

Solution 20 - node.js

This PowerShell script worked to add the correct setting to my environment variable "Path" (as a per-user setting). It adds: %AppData%\npm—and then restart the command line that uses "ng".

$existingPath = [System.Environment]::GetEnvironmentVariable("Path", "User")
Write-Host "existing PATH variable is $existingPath"
$newPath = "%AppData%\npm;$existingPath"
Write-Host "new      PATH will be     $newPath"

# Update here
[System.Environment]::SetEnvironmentVariable("Path", $newPath, "User")

$finalPath = [System.Environment]::GetEnvironmentVariable("Path", "User")
Write-Host "final    PATH variable is $finalPath"

Solution 21 - node.js

The problem is not the install of the NPM nor the path!

If you want to use the "ng" command, you need to install the angular-cli by running the following command

npm install -g @angular/cli

https://cli.angular.io/

Solution 22 - node.js

I resolved it by following the below steps:

  1. Right click on command prompt
  2. Run as administrator
  3. Type npm install -g @angular/cli

Solution 23 - node.js

Exit everything and run npm i -g @angular/cli in a command prompt

And build your Angular application there itself (do not build on PowerShell).

Solution 24 - node.js

I was using npm (5.5.1). Updating it to the latest version solved my problem.

Solution 25 - node.js

You can also make sure you run the Command Prompt - or whatever terminal you use - As Administrator. I am using Visual Studio Code and the ng serve command gives me that exact error when not running Visual Studio Code as an administrator.

Solution 26 - node.js

Run PowerShell or command prompt not as administrator.

Solution 27 - node.js

After changing the path you have to restart PowerShell. You do not need to restart your computer.

Solution 28 - node.js

Based on the previous answers, here is the consolidation.

  1. Run the command npm install -g @angular/cli@project_version

  2. Add the below paths to your environment variables → System VariablesPath (for which administrator access is required).

    C:\Users\YourPcAccountName\AppData\Roaming\npm
    C:\Users\YoutPcAccountName\AppData\Roaming\npm\node_modules\angular-cli\bin
    

    Make sure the first value listed as %AppData%\npm

  3. Reopen your command prompt from your project folder and run ng serve.

Solution 29 - node.js

I ran the 'ng serve' command in the command prompt. It compiled the project successfully. Then whatever changes are saved in Visual Studio Code, are automatically refreshed in the browser.

PS: I have installed Angular globally.

Solution 30 - node.js

Also you can run the following command to resolve it:

npm install -g @angular/cli

Solution 31 - node.js

Please also make sure that the node_modules folder also exists there in the project directory. If it is not there you will get a similar issue. So please run npm install as well.

Solution 32 - node.js

Even though the correct answers have been given, all of these didn't work for me because:

  • My username didn't have the Administrator privileges and I couldn't update the environment variable like suggested in the answers.

Here is what I did:

Instead of ng serve, I copy-pasted the complete location path of ng like the following and it worked.

So the ng serve command became:

C:\Users\MyUserName\AppData\Roaming\npm\ng.cmd serve

Solution 33 - node.js

Reinstalling Node.js is also an option. It will set the PATH variable automatically.

Solution 34 - node.js

In the "Environment Variables"

In the "System variables" section

In the "Path" variable and before "C:\Program Files (x86)\nodejs" add => "%AppData%\npm"

And also do:

npm install

Then restart your Visual Studio Code. This worked for me.

Solution 35 - node.js

It is helped for me (for Windows):

  1. Delete folders:

    C:\Users\**YourName**\AppData\Roaming\npm
    C:\Users\**YourName**\AppData\Roaming\npm-cache
    
  2. Install Node.js from https://nodejs.org/en/download/

  3. In the terminal:

    npm install -g @angular/cli
    

Solution 36 - node.js

Set-ExecutionPolicy RemoteSigned -Scope CurrentUser

This worked for me.

Solution 37 - node.js

You can use:

npm run build:prod

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionWaunaView Question on Stackoverflow
Solution 1 - node.jsjonrsharpeView Answer on Stackoverflow
Solution 2 - node.jsAhmadreza FarrokhnejadView Answer on Stackoverflow
Solution 3 - node.jsArun SurawatView Answer on Stackoverflow
Solution 4 - node.jsA. MorelView Answer on Stackoverflow
Solution 5 - node.jsKRIPA SHANKAR JHAView Answer on Stackoverflow
Solution 6 - node.jsRayan AlbouniView Answer on Stackoverflow
Solution 7 - node.jsRut ShahView Answer on Stackoverflow
Solution 8 - node.jsR15View Answer on Stackoverflow
Solution 9 - node.jsSandeep NandeyView Answer on Stackoverflow
Solution 10 - node.jsKirubelView Answer on Stackoverflow
Solution 11 - node.jsshambhu yadavView Answer on Stackoverflow
Solution 12 - node.jsAleHulkView Answer on Stackoverflow
Solution 13 - node.jsPrafulPravinView Answer on Stackoverflow
Solution 14 - node.jsBrijesh RayView Answer on Stackoverflow
Solution 15 - node.jsHaiNMView Answer on Stackoverflow
Solution 16 - node.jsrfcdejongView Answer on Stackoverflow
Solution 17 - node.jsChathuranga RanasinghaView Answer on Stackoverflow
Solution 18 - node.jsnovice developerView Answer on Stackoverflow
Solution 19 - node.jsDeepa View Answer on Stackoverflow
Solution 20 - node.jsDavB.csView Answer on Stackoverflow
Solution 21 - node.jsSuma MandavaView Answer on Stackoverflow
Solution 22 - node.jsvidhya cView Answer on Stackoverflow
Solution 23 - node.jsAditya ChoudhariView Answer on Stackoverflow
Solution 24 - node.jsmonofalView Answer on Stackoverflow
Solution 25 - node.jsdvlscView Answer on Stackoverflow
Solution 26 - node.jsdustydojoView Answer on Stackoverflow
Solution 27 - node.jsSteve ScottView Answer on Stackoverflow
Solution 28 - node.jsSasikumarView Answer on Stackoverflow
Solution 29 - node.jsRohit ParabView Answer on Stackoverflow
Solution 30 - node.jsBrijesh RayView Answer on Stackoverflow
Solution 31 - node.jsNoNaMeView Answer on Stackoverflow
Solution 32 - node.jsSU7View Answer on Stackoverflow
Solution 33 - node.jsRut ShahView Answer on Stackoverflow
Solution 34 - node.jspranay vooreView Answer on Stackoverflow
Solution 35 - node.jsYudgineView Answer on Stackoverflow
Solution 36 - node.jspankaj pedeView Answer on Stackoverflow
Solution 37 - node.jsuser1960740View Answer on Stackoverflow