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

54,737

Solution 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

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

This worked for me, above trying above which did not work in my case.

Run this command -> Set-ExecutionPolicy RemoteSigned -Scope CurrentUser

Reference:

http://www.techtutorhub.com/article/Getting-ng-File-AppData-Roaming-npm-ng-ps1-cannot-be-loaded-The-file-npm-ng-ps1-is-not-digitally-signed-Angular-Error-when-running-commands/62

Solution 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

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

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
Share:
54,737
R15
Author by

R15

Updated on February 18, 2022

Comments

  • R15
    R15 about 2 years

    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
    
  • R15
    R15 almost 4 years
    From where do I need to execute it?
  • CorrM
    CorrM almost 4 years
    anywhere not important, it's global install.
  • Sajeetharan
    Sajeetharan almost 4 years
    interesting you have node and npm installed? you ran it as administrator?
  • R15
    R15 almost 4 years
    After doing it, I am able to create project from cmd but VS code still not running ng command.
  • CorrM
    CorrM almost 4 years
    if u not close the vs code after install CLI, try restarting. and show your result
  • R15
    R15 almost 4 years
    I have node.js and npm as given above env variable pl check. I ran above cmd as admin still VS code showing error.
  • Sajeetharan
    Sajeetharan almost 4 years
    i can clearly see angular cli installed, i think you are doing something silly
  • R15
    R15 almost 4 years
    And that silly I have been doing since yesterday. What could be the possible reason?
  • Sajeetharan
    Sajeetharan almost 4 years
    may be try to execute that in command prompt and see
  • Sajeetharan
    Sajeetharan almost 4 years
  • Billdr
    Billdr over 2 years
    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.