'ng : The term 'ng' is not recognized as the name of a cmdlet, function Visual Studio Code Terminal
In VS Code when I am running command ng build
, getting error
PS D:\Dashboard\Test1> ng build
ng : 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.
At line:1 char:1
+ ng build
+ ~~
+ CategoryInfo : ObjectNotFound: (ng:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
I have added these environment variable in Path
%USERPROFILE%\AppData\Local\Microsoft\WindowsApps;
C:\Users\Avind\AppData\Local\Programs\Microsoft VS Code\bin;
C:\Users\Avind\AppData\Roaming\npm;
How can I get rid of this issue?
Note: I have node.js
at C:\Program Files\nodejs
. From command prompt ng new project
not working but working from node.js
command.
Edit 1: After executing npm install -g @angular/cli@latest
from VS Code terminal getting below msg and ng
cmd not working
PS D:\Path\Test1> npm install -g @angular/cli@latest
npm WARN deprecated [email protected]: request has been deprecated, see https://github.com/request/request/issues/3142
C:\Users\Avind\AppData\Roaming\npm\ng -> C:\Users\Avind\AppData\Roaming\npm\node_modules\@angular\cli\bin\ng
> @angular/[email protected] postinstall C:\Users\AR20095474\AppData\Roaming\npm\node_modules\@angular\cli
> node ./bin/postinstall/script.js
+ @angular/[email protected]
updated 1 package in 53.477s
Solution 1:[1]
You need to install the latest angular cli to make the ng command work, you can run it from the command termial or visual studio code terminal
npm install -g @angular/cli@latest
if still not working, uninstall and reinstall node.js
from program and feature
.
Solution 2:[2]
As here Angular CLI, Make sure you installed Angular CLI
You can run this command from anywhere on your system
npm install -g @angular/cli
ng --version
Should print something like that
_ _ ____ _ ___
/ \ _ __ __ _ _ _| | __ _ _ __ / ___| | |_ _|
/ ? \ | '_ \ / _` | | | | |/ _` | '__| | | | | | |
/ ___ \| | | | (_| | |_| | | (_| | | | |___| |___ | |
/_/ \_\_| |_|\__, |\__,_|_|\__,_|_| \____|_____|___|
|___/
Angular CLI: 13.1.2
Node: 16.13.1
Package Manager: npm 8.1.2
OS: win32 x64
Angular:
...
Package Version
------------------------------------------------------
@angular-devkit/architect 0.1301.2 (cli-only)
@angular-devkit/core 13.1.2 (cli-only)
@angular-devkit/schematics 13.1.2 (cli-only)
@schematics/angular 13.1.2 (cli-only)
Solution 3:[3]
This worked for me, above trying above which did not work in my case.
Run this command -> Set-ExecutionPolicy RemoteSigned -Scope CurrentUser
Reference:
Solution 4:[4]
Method 1:
Step1:Run the command "Set-ExecutionPolicy RemoteSigned -Scope CurrentUser"
When you run this command, you can see that your system has set all policies for the current user as remotely. It will take few seconds to complete this process.
Step2:enter image description here Get-ExecutionPolicy -list When you run this command, a few policies are shown on your monitor screen Verify if policy for current user is RemoteSigned. ->If YES this should work now. If NO please try Method 2 as below:
Method 2: Find the file "ng.ps1" in path C:\Users%username%\AppData\Roaming\npm\ and remove it from the directory. if you don't know the file extension then right click on the file->got to properties and check the extension of file.
Note:-Please do not remove any other file. Make sure you are removing ng.ps1 file only.
Solution 5:[5]
I received a similar error while working with Powershell and I used the following command to resolve it:
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
Solution 6:[6]
Try commond
npm install -g @angular/cli@latest
then use following:- 1. Open Windows PowerShell 2. run
set-ExecutionPolicy RemoteSigned -Scope CurrentUser
Get-ExecutionPolicy
and you get
RemoteSigned
3. run
Get-ExecutionPolicy -list
you get
Scope ExecutionPolicy
----- ---------------
MachinePolicy Undefined
UserPolicy Undefined
Process Undefined
CurrentUser RemoteSigned
LocalMachine Undefined
Solution 7:[7]
I had the same issue. I reopened CMD in a new tab and typed the same thing like this:
ng g c componentname
and hit Enter, it worked for me.
Solution 8:[8]
This issue may be due to the environment variable not being set. This worked for me:
Run:
npm uninstall -g angular-cli
npm uninstall --save-dev angular-cli
npm install -g @angular/cli
After installing, you enter Advanced System Configuration -> Environment Variables -> Path -> Edit
If this Angular variable is not in the path, you add: "C:\Users\youruser\AppData\Roaming\npm"
Close the terminal, open it and run the command again
Solution 9:[9]
You need to install the latest angular cli to make the ng command work, you can run it from the command terminal or visual studio code terminal.
#> npm install -g @angular/cli@latest
If still not working, uninstall and reinstall node.js from program and feature.
Solution 10:[10]
I solved this problem by just running these three commands:-
npm uninstall -g @angular/cli angular-cli
npm cache clean or npm cache clean --force
npm install -g @angular/cli@latest
It's worked.
Solution 11:[11]
4 steps to fix:
- Uninstall node.js and
- Go to website: https://nodejs.org/en/
- reinstall with the latest LTS (see image below)
- Finally, try the accepted answer above again.
LTS - stands for long term support
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow