Message "the term 'ng' is not recognized as the name of a cmdlet"
node.jsAngularPowershellNpmAngular Clinode.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:
- Right Clicked on My Computer (windows)
- Selected Advanced System Settings
- Clicked "Environment Variables"
- 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
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:
- Win + S. This will open a search box
- Type Edit Environment Variables
- Open Environment Variables
- Add
%AppData%\npm
insidePATH
- 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
- I right-clicked on My Computer (Windows)
- Selected Advanced System Settings
- Clicked "Environment Variables"
- 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
-
Go to project location via command prompt:C:\Users\brijeshray\ParentChild>
-
Reinstall or update existing angular as:
npm install -g@angular/cli@latest
-
Go to computer or PC → Properties → Advanced system setting → Environment Variable → add a path below "User variable" (if 'Path' not there) → C:\Users\brijeshray\AppData\Roaming\npm → save it and restart Visual Studio Code
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
Clicked "Environment Variables"
Under "Path" variable, made the first value listed to be %AppData%\npm
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
Solution 22 - node.js
I resolved it by following the below steps:
- Right click on command prompt
- Run as administrator
- 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.
-
Run the command
npm install -g @angular/cli@project_version
-
Add the below paths to your environment variables → System Variables → Path (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
-
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):
-
Delete folders:
C:\Users\**YourName**\AppData\Roaming\npm C:\Users\**YourName**\AppData\Roaming\npm-cache
-
Install Node.js from https://nodejs.org/en/download/
-
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