ng is not recognized as an internal or external command
Asked Answered
E

55

393

Running windows 7 Professional 32bit.

I tried running npm install -g angular-cli both under normal or admin. 2016-06-23_14h46_40

I also tried adding it to the Enviorment Variables under PATH: (C:\Users\Administrator\AppData\Roaming\npm\node_modules\angular-cli\bin\ng) , with no success also.
2016-06-23_14h56_48

What am i doing wrong?

Erubescence answered 23/6, 2016 at 12:24 Comment(15)
Surely you want the directory (C:\Users\Administrator\AppData\Roaming\npm\node_modules\angular-cli\bin) in %PATH%?Gorham
I'm not sure. I tried it just to see if 'ng' works, but it doesn't.Erubescence
Did you open a new command prompt? Environment variables won't be propagated to running ones. Try echo %PATH% to see that it's correct.Gorham
Well, check that %PATH% contains (it's a semicolon-separated list) the directory that contains ng.exe.Gorham
the path is in there, check it out: lh3.googleusercontent.com/-m3lh5ob7YQY/V2vbE82_KAI/AAAAAAAATsI/…Erubescence
That doesn't look like a path to a directory. Isn't the directory called bin, and the file in the directory called ng.exe?Gorham
I think i know what u mean. U say it should stop at \bin, and not at \bin\ng, and you are right! But do you know how can i edit that path? I just did npm install -g angular-cli and it must have set the wrong path.Erubescence
You said you added it in System Properties > Environment Variables. Just edit it there.Gorham
Could you post the output of dir C:\Users\Administrator\AppData\Roaming\npm\node_modules\angular-cli\bin (better copy the path from %PATH%)?Gorham
In that folder it's a ng file with no extension that has javascript code. It's not an exe. Here is a pic with the output: lh3.googleusercontent.com/-fZYHp-H2nQ8/V2v2qUlEFHI/AAAAAAAATsY/…Erubescence
Possible duplicate of What is the reason for 'sort' is not recognized as an internal or external command, operable program or batch file?Hectocotylus
First I updated 'node' then run '@angular/cli' command in administrator mode, It's fixed my issue.Cavalierly
i found the solution for that problem https://mcmap.net/q/87872/-39-ng-39-is-not-recognized-as-an-internal-or-external-command-duplicateMassarelli
@Cristian Muscalu Or you can simply run cmd as admin (if you can) and install angular-cli from there. so environment variables would be automatically fixed for you.Cameliacamella
Here's an in depth article that halped me, how to fix ng is not recognized as internal or external commandEpicarp
E
22

I solved it few days ago, after having the same problem with other global modules, by adding to:

Environment Tables -> System variables -> Path:

C:\Users\Administrator\AppData\Roaming\npm\node_modules\angular-cli\bin;C:\Program Files\MongoDB\Server\3.2\bin

Note that it must not have any spaces after ;

That turned out to be my problem.

Erubescence answered 1/7, 2016 at 9:47 Comment(4)
Look up the path for file ng.cmd. Update the environment variable PATH value with the same path path. Restart the command line console and you are done.Rodarte
The answer below "npm config get prefix" is the correct approachDownbeat
unless you see the ng in the folder is ng.cmd or Windows Command Script under Type column, else this ng in this angular-cli\bin does not work.Hanna
this answer needs updating, as now the path in CLI v7.0+ is C:\Users\UserName\AppData\Roaming\npmIntangible
M
514

I solved this problem in accordance with the figure:

run in cmd

 npm install -g @angular/cli

and then

( open in Windows 10) Control Panel\All Control Panel Items\System or accordance with the figure

step 1:

enter image description here

step 2 :

enter image description here

step3:

enter image description here

step4:

enter image description here

step5: add missing ng path

C:\Users\{your username}\AppData\Roaming\npm
C:\Users\{yourusername}\AppData\Roaming\npm\node_modules\@angular\cli\bin

enter image description here

Here is new environment variable that you need add: C:\Users\PK\AppData\Roaming\npm\node_modules\@angular\cli\bin

Finally, restart all opened command prompts and try again.

Minim answered 6/9, 2017 at 2:53 Comment(13)
you got the Angular and NG comments (in res) the wrong way round ;)Cratch
in my case i only needed to add the path to npm.Coelenteron
You don't have to restart the computer at the end, u just have to restart the command prompt.Skipjack
Or you can log off ("sign out" in win 10 language), and then log back on. That will "reset" all your environment variables. But that is small potatoes....next to the this actual-answer. Upvote. Thanks.Epidote
C:\Users\<YOURUSER>\AppData\Roaming\npm is not Angular path but npm path, so if you add this path to your environmental variables, then all the npm packages you install with -g flag will be available on your command line (not only ng).Pickwickian
Thanks a lot for the amazing explanation and details. Worked like a charm. Running on Windows 10 and I didn't needed to reboot.Snipe
Perfect, after pulling my hairs for 5 hours I got this correct solution. Thank you very much @BehrouzMoslem. My errors are gone and now I run angularCli commandsGelatinous
Rather than C:\Users\<YOURUSER>\AppData\Roaming\npm, you can use %USERPROFILE%\AppData\Roaming\npm without having to type in your username.Incinerator
In my situation, order lines has been effected to work. When I firstly enter @angular line, and after npm line is not worked ( In Visual Studio Code ). Thanks.Hogg
%appdata%\npm\node_modules\@angular\cli\bin is enough. No need for absolute path.Catwalk
This instructions are overcomplicated, just hit the WINDOWS key and type "Environment" to go to the environment variablesLivy
For Windows and Bash usage, I ended up adding the following to my ~/.bashrc in order to get things working. PATH=$PATH:~/AppData/Roaming/npm:~/AppData/Roaming/npm/node_modules/@angular/cli/binThadeus
no need to restart command lines after put the pathMccowan
E
354

For me it works with:

npm run ng <command>
Eudemonism answered 29/3, 2017 at 13:9 Comment(9)
Do you know the reason why it is so and how can we get rid of 'npm run' ?Cobra
but this does omit any additional parameters after ng buildProvence
For direct running through ng command you can link your @angular/cli with npm using npm link @angular/cliSamothrace
@PratikGandhi This is because cmd can only run commands specified in the environment variables (in this case npm). This path is added when you install node in your system globally. When you add the complete path C:\Users\<user>\AppData\Roaming\npm\node_modules\@angular\cli\bin\ng to environment variables and rerun cmd, it will accept ng as a command. Alternatively, you can also use Node.js command prompt to run ng commands.Obstetrics
@Provence You can pass in additional parameters to the ng command via npm run ng serve -- --port=12345. Note the two separate sets of dashes.Toadfish
This also applies if you setup your Angular project via Visual Studio template.Cavell
npm, but also yarn or another package managerLibelous
I wanted to run ng serve -o and have the browser open up a tab automatically, so using the example provided by @krillgar, that became npm run ng serve -- -oRecital
@Cobra the reason could be your node version changed!Idioblast
C
139

Adding C:\Users\DELL\AppData\Roaming\npm to System Variable Path worked for me. Please find your appropriate file path to 'npm'

Also, check if you have added your angular-cli\bin path to the path variable.

Corwun answered 11/11, 2016 at 14:21 Comment(5)
Also try restarting PC. After that ng command started working.Garrett
Look up the path for file "ng.cmd". update the environment variable PATH with the path.Rodarte
This worked for me on Windows 10, but I added "%USERPROFILE%\AppData\Roaming\npm" to cover multiple potential users pulling from their own user profiles.Acaroid
%AppData%\npm will expand to both @TimMcElwee and @sabari's values, and are user and machine agnostic.Abiogenetic
adding the \npm folder to path variables fixed it for meEcliptic
M
98

I am using WIN 10, just figure it out for this problem. Type the code below in cmd:

npm config get prefix

and copy&paste the path that you get it from the top into your computer environment variables-->user variables box --> path --> edit -- C:\Program Files\nodejs\node_global, your path may different.

Click Ok and reopen your cmd window, type in ng version, then it works! Cheers!

Malvia answered 19/6, 2017 at 4:19 Comment(3)
Works like a charm! MySQL shell overrode my user path variable.. :(Giselle
Didn't work for me. npm config get prefix told me my directory was C:\Users\PhilVanKleur\AppData\Roaming\npm\ . But there's nothing in it.Posthaste
This worked perfectly for me in Win 10 on my Dev box. I have also installed Chocolatey and ran the "refreshenv" command after adding the folder which was yielded into the user environment PATH variable and avoided to have to refresh my terminal window.Dunlin
S
54

Just open your command prompt (run as administrator). Ensure node --v is 6.9.0 or higher and npm --v is 3.0.0 r higher.

After that run the following command:

npm install -g @angular/cli

Once angular is installed. you can see an entry of angular cli in the path

C:\Users\Dell\AppData\Roaming\npm\node_modules\@angular

Then try ng help. It will work.

Steradian answered 28/6, 2017 at 13:48 Comment(1)
running as administrator seems to be the key bitAgue
H
50

1) Enter below command on command prompt

npm install -g @angular/cli

2) Make sure that C:\Users\_username_\AppData\Roaming\npm this path is not hidden.

3) Add C:\Users\_username_\AppData\Roaming\npm and

C:\Users\_username_\AppData\Roaming\npm \node_modules@angular\cli\bin to both enviroment variable path.

4) Open new command prompt and type ng help. It will work.

Headrest answered 9/10, 2019 at 10:31 Comment(2)
I could not see the AppData directory until I got admin permission for my Windows 10 machine and then opened up a command window by clicking Run as Administrator.Brakesman
I had that folder hidden but it still worked. This is the best solution. As an FYI if needed: you separate the paths with a semi-colon so it becomes: <what's already there>;C:\Users\_username_\AppData\Roaming\npm;C:\Users\_username_\AppData\Roaming\npm \node_modules@angular\cli\binSuzannesuzerain
C
23

With a command

npm install -g @angular/cli@latest

It works fine, I am able to run ng command now.

Contusion answered 5/4, 2018 at 10:7 Comment(1)
I ran npm install -g @angular/cli@latest from folder c:\Temp. It did not install to C:\Users_username_\AppData\Roaming\npm \node_modules@angular\cli\bin. It created C:\Temp\node_modules instead. I'm very new to this but I thought -g (global) would put it in ..Appdata\Roaming\npm..Litman
E
22

I solved it few days ago, after having the same problem with other global modules, by adding to:

Environment Tables -> System variables -> Path:

C:\Users\Administrator\AppData\Roaming\npm\node_modules\angular-cli\bin;C:\Program Files\MongoDB\Server\3.2\bin

Note that it must not have any spaces after ;

That turned out to be my problem.

Erubescence answered 1/7, 2016 at 9:47 Comment(4)
Look up the path for file ng.cmd. Update the environment variable PATH value with the same path path. Restart the command line console and you are done.Rodarte
The answer below "npm config get prefix" is the correct approachDownbeat
unless you see the ng in the folder is ng.cmd or Windows Command Script under Type column, else this ng in this angular-cli\bin does not work.Hanna
this answer needs updating, as now the path in CLI v7.0+ is C:\Users\UserName\AppData\Roaming\npmIntangible
D
22

I followed below steps for resolution for this issue in Windows 10:

  1. First make sure you have installed Angular CLI . You can use below to install same.

npm install -g @angular/cli@latest

  1. Make sure that AppData is visible and navigate to path below.

C:\Users\rkota\AppData\Roaming\npm

Same path can be found by running below too:

npm config get prefix

  1. Add the above path i.e. " C:\Users\rkota\AppData\Roaming\npm" in Environment variable PATH and make sure it got added by running path in command prompt.
  2. Close command prompt and now try to run below:

ng --version

you will be able to see CLI version.

Delinda answered 24/6, 2019 at 10:12 Comment(0)
Z
19

General problem is that OS tries to find the PATH variable with ng keyword and cannot find it. For me, even after the steps @behrouzmoslem suggested in the top answers to this post I didn't manage to get it work, because after the launch of ng command OS started to respond, but opens up editor file by the path C:\Users\{username}\AppData\Roaming\npm\node_modules\@angular\cli\bin\ng which is actually funny. So, solution is:

Just use npx before any angular executables.

Eg : npx ng serve for serving the angular app or npx ng build --watch to build with watcher.

Zahara answered 19/5, 2021 at 10:34 Comment(1)
Finally! Something that works. I have to run everything from a separate admin account on my machine due to my organisation's security policies. This is the first solution that worked for me.Invulnerable
A
17

execute following lines in order to solve the issue for both not found and undefined version of ng

npm uninstall -g angular-cli

npm uninstall --save-dev angular-cli

npm cache clean

npm install -g @angular/cli@latest

Airspeed answered 24/2, 2018 at 16:21 Comment(0)
G
13

Instead of using the in-built command prompt better start using the NodeJS installed version of command prompt. Then it is going to work perfectly without any issues.enter image description here

Godolphin answered 27/9, 2017 at 12:0 Comment(1)
Running where ng within that console might help to find out what is wrong with the path. That did it for me, ng was resolved in the wrong user AppData, hence executing a bad version of the cli.Ellga
A
12

If you get the error even after following the above step. then try below.

Since it is a node script. I am using the below option to create as of now.

node C:\Users\Administrator\AppData\Roaming\npm\node_modules\angular-cli\bin\ng version

May be symbolic links are required. Not researched further.

On Further Research: Set Path as : %PATH%;C:\Users\Administrator\AppData\Roaming\npm;

In Windows, npm.cmd file is in the above path. If the above Environment variable is set, you can execute as ng version ng init

Aim answered 19/8, 2016 at 7:56 Comment(0)
A
9

for me it works only with the flag --force:

npm install -g @angular/cli --force

If everything is fine then you shoud see the folder node_modules in this path:

C:\Users\YOUR_USERNAME\AppData\Roaming\npm\
Anorexia answered 11/1, 2022 at 12:9 Comment(1)
It's working. thanks. Most of office system is shared workspace like citrix. so, we can't find C drive. But this command will helps to do ng version avail globally. thanksTopflight
B
8
  1. Open cmd and type npm install -g @angular/cli

  2. In environment variables, add either in the user variable or System variable "Path" value=C:\Users\your-user\.npm-packages\node_modules\.bin

  3. In cmd: c:\>cd your-new-project-path

  4. ...\project-path\> ng new my-app

    or ng all-ng-commands

Bewhiskered answered 6/8, 2017 at 7:25 Comment(0)
P
8

I resolved by adding - %AppData%\npm\node_modules@angular\cli\bin\ path to my environment variables path

Parris answered 20/3, 2020 at 11:14 Comment(0)
P
6

close cmd and open it again with admin right or reboot ur system.

Penang answered 26/6, 2016 at 19:54 Comment(0)
D
6

I faced same issue when i tried to install angular cli locally with command

npm install @angular/cli@latest

After that i got same issue C:\Users\vi1kumar\Desktop\tus\ANGULAR\AngularForms>ng -v 'ng' is not recognized as an internal or external command, operable program or batch file

Than i tried to install it globally

npm install -g @angular/cli@latest

In this case it worked I was wondering that is it not possible to install cli globally ?

After doing some research I found this article very helpful hope it will help someone facing similar issue

Working with multiple versions of Angular CLI

Disintegrate answered 14/3, 2019 at 3:4 Comment(0)
G
5

This one almost worked for me, but I had to use: %USERPROFILE%\AppData\Roaming\npm . In Environment Variables.../System variables/Path

Then when I did CMD: "ng -v" I got the correct response for angular cli.

Goblet answered 24/5, 2017 at 20:31 Comment(0)
S
5

npm install -g @angular/cli helped for me instead of npm install @angular/cli

Sommelier answered 28/5, 2018 at 14:45 Comment(0)
R
5

1- Install

$ npm install -g @angular/cli

2- Make sure where your ng.cmd is present.

enter image description here

3- Then add this path into variables.

enter image description here

Reedy answered 26/9, 2019 at 0:58 Comment(0)
M
3

I had the same problem on Windows 7, 64 bits running with npm v3.10.8.

  1. I added the path as it was suggested: ( C:\Users.....(your user name)\AppData\Roaming\npm\node_modules\angular-cli\bin\ng) and uninstalled angular-cli.
  2. After this, I cleared the npm cache by npm cache clean as prompted here https://blogs.msdn.microsoft.com/matt-harrington/2012/02/23/how-to-fix-node-js-npm-permission-problems/. This guarantees there are no leftovers.
  3. Reinstalled angular-cli with npm install -g angular-cliand voila.

    Hope that may be useful!
Merv answered 9/2, 2017 at 19:32 Comment(0)
J
3

In my case I did below steps.

All Programs -> Node JS-> Right click on Node.js Command Prompt and select properties and from Target string at end copy below

/k "C:\Program Files\nodejs\nodevars.bat"

I launched Visual Studio Code and opened below file

C:\Users\gochinta\AppData\Roaming\Code\User\settings.json and gave below

// Place your settings in this file to overwrite the default settings
{
  "terminal.integrated.shellArgs.windows": 
  ["/k", "C:\\Program Files\\nodejs\\nodevars.bat"]

}

Now I typed ng -v in my Visual Studio Code Terminal window and it worked.

Jessamyn answered 17/4, 2017 at 22:37 Comment(0)
A
3

I was having the same issue when tried with the syntax "ng new " and solved that simply by updating the existing node version from 5.x.x to 8.x.x. After successful updation of node, the syntax worked perfectly for me. Please update the existing version of node. As it is clearly mentioned in angular documentation that these commands require the node version >= 6.9.x. For reference please check https://angular.io/guide/quickstart. It clearly states "Verify that you are running at least node 6.9.x and npm 3.x.x by running node -v and npm -v in a terminal/console window. Older versions produce errors, but newer versions are fine".

Anglice answered 22/6, 2017 at 11:17 Comment(0)
I
3

I faced same issue on x86, windows 7;

  • uninstalled @angular/cli
  • re-installed @angular/cli
  • checked & verified environmental variables (no problems there)...
  • Still same issue:

Solution was the .npmrc file at C:\Users{USERNAME}... change the prefix so that it reads "prefix=${APPDATA}\npm"... Thanks to this website for help in resolving it

Icelander answered 11/10, 2017 at 9:32 Comment(0)
R
3

For me something was wrong in the PATH enviroment variable. I removed all path related to npm and added at the start of PATH this folder:

c:\Users\<your-user-name>\AppData\Roaming\npm\

Make sure you have ; between paths.

Revels answered 7/6, 2018 at 5:15 Comment(1)
this is the right one, because both Win7 & 10 have ng. cmd file here.Hanna
F
2

Since this question is still asked over and over again one year later I will post my answer here as well.

The clue (on Windows only) is to arrange the entries in the path variable right.

As the NPM wiki tells us:

Because the installer puts C:\Program Files (x86)\nodejs before C:\Users\\AppData\Roaming\npm on your PATH, it will always use version of npm installed with node instead of the version of npm you installed using npm -g install npm@<version>.

So your path variable will look something like:

…;C:\<path-to-node-installation>;%appdata%\npm;…

Now you have two possibilities:

  1. Swap the two entries so it will look like
…;%appdata%\npm;C:\<path-to-node-installation>;…

This will load the npm version installed with npm (and not with node) and with the installed Angular CLI version.

  1. If you (for whatever reason) like to use the npm version bundled with node, add the direct path to your global Angualr CLI version. After this your path variable should look like this: …;C:\Users\<username>\AppData\Roaming\npm\node_modules\@angular\cli;C:\<path-to-node-installation>;%appdata%\npm;… or …;%appdata%\npm\node_modules\@angular\cli;C:\<path-to-node-installation>;%appdata%\npm;… for the short form.

This worked for me since a while now.

Furgeson answered 8/10, 2017 at 15:1 Comment(0)
B
2

I am facing same issue and it's get resolved. At my end reason is i install node and CLI using other user profile and now i am running ng command from other user login. Since node and cli installed using other user login node is not finding anything on C:\Users\&lt;user name&gt;\AppData\Roaming this path and that's why i am getting this error.

I run npm install -g @angular/cli command and restart my machine. Every thing is working fine.

Bengt answered 26/12, 2017 at 15:15 Comment(0)
D
2

Sometime in the future. Applicable to Windows 8.1 machine. Run the following commands

npm install -g @angular/cli

Log out or restart your machine.

This should add the required env path, rather than doing it manually.

Die answered 9/10, 2018 at 4:51 Comment(0)
B
2

I also tried to play with cmd by setting environment variable path & etc, but simple answer is use nodejs command prompt.

So you no need to set environment variable path or anything. When you insalled nodejs it will give it's command prompt, by using that you us "ng" command, without any settings.

Bozeman answered 22/10, 2018 at 11:22 Comment(0)
C
1

I had the same issue of Visual Studio Code not being able to run any ng commands in it's built in terminal.

I added %AppData%\npm to the path in Windows 10, and did not have to reboot, just closed and reopened VS Code and not it sees it.

Cambrai answered 15/8, 2017 at 19:46 Comment(1)
same issue i set new path to AppData\Roaming\npm\node_modules\@angular\cli\bin\ng and it works fine nowSlub
W
1

Install x32 version nodejs instead of x64 version (even on 64-bit windows machine).

Wiltonwiltsey answered 28/8, 2017 at 9:44 Comment(2)
Run npm run ng serve for a dev server. Navigate to http://localhost:PORT YOU DEFINE IN APPSETTINGS/. The app will automatically reload if you change any of the source files.Audry
@NitishKumar , Why a x32 version instead of x64 on a 64-bit windows?Gatekeeper
S
1

I was also following this problem so I tried this command and it worked perfectly. Use this command: npm run ng

Scarito answered 8/9, 2017 at 12:13 Comment(0)
K
1

I had the same problem today and have gone through the following path - (%USERPROFILE%\AppData\Roaming\npm) and came to know that there is some junk data and when I cleared everything under npm directory. Now when I ran (npm install command again). Now everything works fine.

Krummhorn answered 15/12, 2017 at 6:25 Comment(1)
This helped for me!Stott
B
1

Navigate the directory where you want to create the application and run the command:

PATH="Path where your node is installed";%PATH%

Bax answered 30/5, 2018 at 14:54 Comment(0)
C
1

I had the same problem and solved it completely by running VS Code as Administrator.

I used the above mentioned solutions (npm install -g @angular/cli@latest & npm install @angular/cli in my project), tried ng serve both in cmd and VS Code terminal but didn't work, while npm run ng serve could run in VS Code terminal, but I wasn't satisfied with that. After that I set the path in the environment variables exactly like this "C:\Users\TheUserName\AppData\Roaming\npm" and still wasn't able to run ng serve.

Then I ran VS Code as Administrator and it finally worked. It even recognized another command, gulp, which didn't recognize till then, even though I had it also correctly installed. Not sure why it had this behavior and I would like an explanation.

Capitol answered 6/3, 2019 at 9:38 Comment(0)
D
1

After installation: Go to start Menu Type Environment variable click on "edit the system environment variables", It will open a window In window, click on "Environment variable" button Double click on "Path" then click on new and add the below environment variable C:\Users\\AppData\Roaming\npm (or open run window type %AppData% and open npm folder there. Provide this location in environment variable.)

Doomsday answered 15/5, 2020 at 9:45 Comment(0)
S
1

On Windows 10 pro:

  1. Install Node and restart the device.
  2. Run npm install -g @angular/cli.
  3. Restart system.

Note: Don't forget -g in command.

Seek answered 29/11, 2021 at 15:35 Comment(0)
I
0

Set path=%path%;C:\Users\\AppData\Roaming\npm

Irascible answered 24/5, 2017 at 9:43 Comment(0)
Y
0

PATH environment variable should be updated by adding following path,

C:\Users\xyzname\AppData\Roaming\npm\node_modules\@angular\cli\bin

Because ng file is in bin folder, once this is added for sure ng will be recognized

Yammer answered 12/12, 2017 at 13:18 Comment(0)
F
0

try to set system variable path with %AppData%\npm\. and make sure visibility of AppData folder. this folder should be visible (not hidden).

Fujio answered 7/2, 2018 at 8:16 Comment(0)
M
0

I had to add the npm path to the user PATH environment variable as well. You can do that by running the following PowerShell script as admin:

$path = npm config get prefix    
$userPath = [Environment]::GetEnvironmentVariable("Path", "User")

if (($userPath -split ';') -notcontains $path) 
{
    [Environment]::SetEnvironmentVariable("PATH", ('{0};{1}' -f $userPath, $path), "User")
}
Mechellemechlin answered 4/5, 2018 at 7:44 Comment(0)
N
0

Before try to update the PATH varibles on Windows 7 (x64), run CMD console AS ADMINISTRATOR and ng command works for me, this also applied to VISUAL STUDIO CODE Console.

It worked for me on both CMD CONSOLE / VS CODE

Nevanevada answered 4/7, 2018 at 22:18 Comment(0)
T
0

In my case, even though %appdata%\npm was already in PATH, I had to delete and add it again in the system variable editor. Restarting OS / reinstalling Angular CLI did not help for some reason.

Togoland answered 23/3, 2019 at 8:22 Comment(0)
C
0

Had the same problem on Windows 10. The user's %Path% environment already had the required "C:\Users\ user \AppData\Roaming\npm".

path command would not show it, but it did show tons of other paths added earlier by other installations.

Turned out I needed to delete some of them from the system's PATH environment variable.

As far as I understand this happens because there's a length limit on these variables: https://software.intel.com/en-us/articles/limitation-to-the-length-of-the-system-path-variable

Probably happens often on dev machines who install lots of stuff that needs to be in the PATH.

Chad answered 8/9, 2019 at 17:54 Comment(0)
P
0

Use Node.js command prompt and execute the command

ng version

It should work.


If you're looking to actually find where ng is located you can then type where ng and it will show you which ng is running (eg. C:\Users\USERNAME\AppData\Roaming\npm). You can then look at your path and see if adding that folder is helpful. The Node.js command prompt adds extra paths that may be missing from your path.

Poulterer answered 22/9, 2019 at 7:34 Comment(1)
Ok so this is an interesting answer. I change my user home directory (to remove a space) and then my ng was no longer in the path. I've edited the answer to add next steps.Dealer
M
0

I don't have a global Angular install, only project level. One of my projects kept throwing this error while others with same setup worked fine! I just

  1. Removed the node_modules folder from the project
  2. Ran npm i in the project

Works fine now.

Midday answered 7/10, 2019 at 17:17 Comment(0)
G
0

For those using Yarn

After doing a yarn global add @angular/cli the ng command was not recognized even after cmd window restart.

The solution for me was to add either

  • C:\Users\<username>\AppData\Local\Yarn\bin to the USER environment variable PATH
  • %LOCALAPPDATA%\Yarn\bin to the SYSTEM environment variable PATH.

Installing Yarn with npm install -g yarn did not add those paths for me for some reason, idk if it should or shouldn't but I cant remembering needing to do so previously on other machines I have had.

Gregory answered 12/5, 2021 at 10:21 Comment(0)
S
0

If you are looking for a solution to avoid global installation of angular cli. You can add script command to package.json as below

"scripts": {
     ....
    "create":"ng g c components/auth-extensions"
  }

and run the command

npm run create

Once your job is done, you can delete the command from package.json.

This avoids installing global package, environment variable, path etc..

Skindeep answered 3/4, 2023 at 6:11 Comment(0)
C
0

If you don't want to install angular cli globally and starting from scratch then try following steps

  1. go to your workspace (cd ./path_to_your_workspace) .

  2. $npm init (This will generate package.json)

  3. $npm i @angular/cli

  4. update package json script section

  5. $npm run ng ... (Add prefix npm run to your angular commands)

      "scripts": {
        "ng": "ng",
        "start": "ng serve",
        "build": "ng build",
        "watch": "ng build --watch --configuration development",
        "test": "ng test",
        "e2e": "ng e2e"   
    }
Cookstove answered 8/9, 2023 at 6:31 Comment(0)
D
0

enter image description here

npm install -g @angular/cli

install this and set path in environment variable

https://angular.io/cli

Project name my-first-project

ng new my-first-project // To create Project

cd my-first-project

ng serve

Defloration answered 13/2 at 13:24 Comment(0)
P
-1

Set the new path to C:\Users\yourname\AppData\Roaming\npm\node_modules\@angular\cli\bin\ng It works fine now for me

Panlogism answered 23/6, 2016 at 12:24 Comment(0)
V
-1

Add the ng command path from the folder .bin under the node_modules to PATH variable in the system env settings.

e.g: add C:\testProject\node_modules\.bin\ to PATH

Restart your IDE.

Vallery answered 5/6, 2018 at 14:25 Comment(0)
W
-1

You can check in this way. I had the same problem. First, check your user PATH in the environment variable.That must point to "%USERPROFILE%\AppData\Roaming\npm\node_modules\@angular\cli\

Instead of command prompt use the node.js command prompt. Run node.js command prompt from installed program menu. Go to start and search for node.js command prompt. Run it then type ng -v hit enter. It will work. Let me know your if it helps or not.

Whaleboat answered 30/7, 2018 at 9:32 Comment(0)
F
-1

Step 1: Right on powershell and Run as Administrator

Step 2: Run below command

Set-ExecutionPolicy Unrestricted -Scope CurrentUser

Step 3: To confirm , run below command, it should display version.

ng version
Festoon answered 13/7, 2023 at 6:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.