Arvind Chourasiya
Arvind Chourasiya

Reputation: 17422

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 [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

Upvotes: 12

Views: 113997

Answers (10)

Sneha Ravichandran
Sneha Ravichandran

Reputation: 119

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

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser

Upvotes: 4

Pooja Burande
Pooja Burande

Reputation: 101

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

Upvotes: 6

P Kiran Kumar
P Kiran Kumar

Reputation: 29

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.

Upvotes: 2

Abhay Kumar Upadhyay
Abhay Kumar Upadhyay

Reputation: 3009

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
    

Upvotes: 2

RetroCoder
RetroCoder

Reputation: 2685

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

Upvotes: 0

Abhay Kumar Upadhyay
Abhay Kumar Upadhyay

Reputation: 3009

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.

Upvotes: 0

Windson Mateus
Windson Mateus

Reputation: 71

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.

Upvotes: 0

CorrM
CorrM

Reputation: 527

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)

Upvotes: 10

Sajeetharan
Sajeetharan

Reputation: 222582

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.

Upvotes: 24

Khadija Ahmed
Khadija Ahmed

Reputation: 9

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.

Upvotes: 0

Related Questions