angularvisual-studio-codeterminalng-build

ng : The term 'ng' is not recognized as the name of a cmdlet, function Visual Studio Code Terminal


In Visual Studio Code, when I am running command ng build, I am getting this 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 variables 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 in C:\Program Files\nodejs. From the command prompt, ng new project is not working, but it is working from a node.js command.

After executing npm install -g @angular/cli@latest from the Visual Studio Code terminal, I am getting the below message and the ng command is not working:

PS D:\Path\Test1> npm install -g @angular/cli@latest
npm WARN deprecated request@2.88.2: 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/cli@9.1.9 postinstall C:\Users\AR20095474\AppData\Roaming\npm\node_modules\@angular\cli
> node ./bin/postinstall/script.js

+ @angular/cli@9.1.9
updated 1 package in 53.477s

Solution

  • 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 it is still not working, uninstall and reinstall Node.js from Programs and Features.