The term "ng" is not recognized as a cmdlet name

Today, while working on some basic introduction to AngularJS, I ran into a problem. I opened PowerShell to get started on a project. NPM worked.

I was able to install Angular using

npm install -g @angular/cli 

Every time I tried to run ng, I got

 the term 'ng' is not recognized as the name of a cmdlet 
+51
source share
22 answers

The first path in the path variable must be an NPM path. Opening the Node.js command prompt, I found that the ng command works there. I rummaged through the shortcut and found that it refers to the command to make sure that the first Path variable is NPM. Fix:

  1. Right click on my computer (Windows)
  2. Selected advanced system settings
  3. Click "Environment Variables"
  4. The "Path" variable contains the FIRST value in the list %AppData%\npm

Once I did this, I was able to close PowerShell and open again, and everything worked.

+64
source

First configure Node.js, then navigate to your project folder using a command line such as D: \ project, and then run this command:

 npm install -g @angular/cli 

Now run the ng command. This is a job for me.

+55
source

In "Environment Variables"

In the "System Variables" section

In the variable "Path" and before "C:\Program Files (x86)\nodejs\" add => "%AppData%\npm"

+14
source

The solution worked for me:

Add a path to your environment Variable

 C:\Users\YourPcName\AppData\Roaming\npm 

as well as your bin folder from the corner file [imagine them]

 C:\Users\YoutPcName\AppData\Roaming\npm\node_modules\angular-cli\bin 

and then run ng -v it ng -v angular text on your command line. Note After starting npm -g @angular/cli restart the command line and check if it works, otherwise clear the cache and repeat the steps above.

+9
source

Installing angular Kli globally solved my problem.

 npm install -g @angular/cli 
+6
source

If the name of your project contains "-". Take it away and try it. This can cause problems with running 'ng'.

+1
source

Instead of issuing the "ng serve" command in the Visual Studio code terminal, open the corner path of the application on the command line (Run as administrator).

Then give the command "ng serve".

Then open a browser and go to http: // localhost: 4200 /

It works for me.

+1
source

Open Change system environment variables

In the variable "Path" and "Path of the PS module" add "% AppData% \ npm"

Run Visual Code as administrator

It works for me!

+1
source

You just need to close the Visual Studio code and restart again. But in order to make the ng command work in the vs code, you first need to compile the project using cmd in administrator mode.

I also ran into the same problem. But this method solved it.

+1
source

This powershell script worked to add the correct parameter to my Path environment variable (as a parameter for the user.) It adds:% AppData% \ npm ... and then restarts the command line using "ng".

  $existingPath = [System.Environment]::GetEnvironmentVariable("Path","User") write-host "existing PATH variable is $existingPath" $newPath = "%AppData%\npm;$existingPath" write-host "new PATH will be $newPath" # update here [System.Environment]::SetEnvironmentVariable("Path", $newPath, "User") $finalPath = [System.Environment]::GetEnvironmentVariable("Path","User") write-host "final PATH variable is $finalPath" 
+1
source

I used npm (5.5.1), updating to the latest version solved my problem.

0
source

You can also make sure that you run the command line - or any terminal that you use - as an administrator. I am using Visual Studio Code, and the ng serve command gives me this error when I do not run VS Code as administrator.

0
source

Start Powershell or a command line other than as an administrator.

0
source

You should upgrade the js node to the latest version. Otherwise, remove the js node and install it again.

0
source

After changing the path, you must restart PowerShell. You do not need to restart your computer.

0
source

i used nodejs command line instead of vscode terminal

0
source

The problem is not installing NPM and not on the go! If you want to use the "ng" command, you need to install angular-cli. by running the following command

 npm install -g @angular/cli 

https://cli.angular.io/

0
source

I decided by following these steps

1. Right-click on the command line. 2. Run as administrator. 3. Type npm install -g @ angular / cli.

0
source

Based on the answers above, consolidation is here.

  1. Run the npm install -g @angular/ cli@project _version
  2. Add the following paths to the environment variables β†’ System variables β†’ Path (which require administrator access).

    C: \ Users \ YourPcAccountName \ AppData \ Roaming \ NPM C: \ Users \ YoutPcAccountName \ AppData \ Roaming \ NPM \ node_modules \ angular cli \ Bin Make sure that the first value is specified as %AppData%\npm

  3. Open the command prompt again from your project folder and run ng serve .
0
source

I ran the command 'ng serve' on the command line. He successfully compiled the project. Then all changes saved in VS Code are automatically updated in the browser.

PS: I installed angular everywhere.

0
source

1) Right-click on my computer (windows) 2) Selected additional system parameters 3) Clicked "Environment Variables" 4) The "Path" variable indicates the first value in the list% AppData% \ npm

Initially : C: \ Program Files \ Microsoft MPI \ Bin \;% SystemRoot% \ system32;% SystemRoot%;% SystemRoot% \ System32 \ Wbem;% SYSTEMROOT% \ System32 \ WindowsPowerShell \ v1.0 \; C: \ Program Files \ TortoiseSVN \ Bin;

After adding the path : C: \ Program Files \ Microsoft MPI \ Bin \; % AppData% \ npm; % SystemRoot% \ system32;% SystemRoot%;% SystemRoot% \ System32 \ Wbem;% SYSTEMROOT% \ System32 \ WindowsPowerShell \ v1.0 \; C: \ Program Files \ TortoiseSVN \ bin;

One more thing you can try if the error still appears, as shown below 1) go to the project location via the command line: C: \ Users \ brijeshray \ ParentChild> 2) Reinstall or update the existing angular as: npm install -g @ angular / cli @latest

3) Go to your computer or PC -> Properties β†’ Advanced system settings β†’ Environment variable β†’ add the path below the β€œUser variable” (if the β€œPath” is missing) ==> C: \ Users \ brijeshray \ AppData \ Roaming \ npm β†’ save him and restart the visual code enter image description here

0
source

You can also run the following command to resolve, npm install -g @ angular / cli

0
source

Source: https://habr.com/ru/post/1269578/


All Articles