12

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 [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
4
  • What does npm config get bin-links return if u execute it in your terminal?
    – kai
    Commented Jun 23, 2020 at 5:28
  • @kai - In VS code terminal saying true. Commented Jun 23, 2020 at 5:30
  • Can u also check that inside C:\Users\Avind\AppData\Roaming\npm there is a file called ng.cmd?
    – kai
    Commented Jun 23, 2020 at 5:31
  • @kai - Yes this file is there in the same path. Commented Jun 23, 2020 at 5:37

10 Answers 10

23

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.

6
  • interesting you have node and npm installed? you ran it as administrator? Commented Jun 23, 2020 at 4:53
  • I have node.js and npm as given above env variable pl check. I ran above cmd as admin still VS code showing error. Commented Jun 23, 2020 at 5:11
  • 1
    i can clearly see angular cli installed, i think you are doing something silly Commented Jun 23, 2020 at 5:18
  • And that silly I have been doing since yesterday. What could be the possible reason? Commented Jun 23, 2020 at 5:26
  • may be try to execute that in command prompt and see Commented Jun 23, 2020 at 5:32
9

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

It should print something like this:

     _                      _                 ____ _     ___
    / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
   / △ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
  / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
 /_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
                |___/


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)
4
  • From where do I need to execute it? Commented Jun 23, 2020 at 4:24
  • anywhere not important, it's global install.
    – CorrM
    Commented Jun 23, 2020 at 4:28
  • After doing it, I am able to create project from cmd but VS code still not running ng command. Commented Jun 23, 2020 at 5:02
  • if u not close the vs code after install CLI, try restarting. and show your result
    – CorrM
    Commented Jun 23, 2020 at 5:06
6

This worked for me. Trying previous answers did not work in my case.

Run this command

Set-ExecutionPolicy RemoteSigned -Scope CurrentUser

Reference:

ng : File \AppData\Roaming\npm\ng.ps1 cannot be loaded. The file npm\ng.ps1 is not digitally signed Angular Error when running commands

0
4

I received a similar error while working with PowerShell, and I used the following command to resolve it:

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
2

Try this command:

npm install -g @angular/cli@latest

Then use the 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
    
2

Method 1:

Step 1: 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.

Step 2: Enter image description here

Get-ExecutionPolicy -list

When you run this command, a few policies are shown on your monitor screen.

Verify if the policy for the current user is RemoteSigned. If yes, this it 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 -> go to Properties and check the extension of file.

Note: Please do not remove any other file. Make sure you are removing the ng.ps1 file only.

1
  • Removing ng.ps1 seems to force the file to be recreated, this time with the proper signature. That seems a lot safer than fiddling with policy.
    – Billdr
    Commented Oct 3, 2021 at 14:42
0

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.

0

This issue may be due to the Path 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 ConfigurationEnvironment VariablesPathEdit.

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.

0

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 worked.

1
  • But not "or" (isn't literal?)? Can you make that clearer? Commented Dec 11, 2022 at 2:29
0

Four steps to fix:

  1. Uninstall Node.js and

  2. Go to website: https://nodejs.org/en/

  3. Reinstall with the latest LTS[1] (see image below)

    Enter image description here

  4. Finally, try the accepted answer above again.

[1]: LTS stands for long term support

Not the answer you're looking for? Browse other questions tagged or ask your own question.