Angular-cli: 'ng' is not recognized as an internal or external command, operable program or batch file.

Created on 29 May 2017  路  11Comments  路  Source: angular/angular-cli

Bug Report or Feature Request (mark with an x)

- [x] bug report -> please search issues before submitting
- [ ] feature request

Versions.

  • node v7.10.0
  • npm v4.2.0
  • Windows 10 Version 1703 build 15063.332

Repro steps.


I installed and uninstalled the cli and node several times and even manually cleaned node caches after uninstalling and it refuses to recognize 'ng'. The installer never fails with no error message. when you call 'ng' it will recognize

The log given by the failure.

C:\Users\awsau>ng help
'ng' is not recognized as an internal or external command,
operable program or batch file.

Desired functionality.

Mention any other details that might be useful.

  • I had done a fresh install of windows using the included program "Fresh Start" that is included with windows before installing the cli.
  • I had previously had this problem a few months ago but fixed it by updating node and cleaning the cache manually.
more info

Most helpful comment

  1. Hit the Windows button ( cmd on Mac ) and write "Environment"

2.

Select the option that says "Environment variables for your account" ( or similar in your own language )

  1. Select Path

  2. 4.

Select New and add "C:\Users\Administrator\AppData\Roaming\npm"

  1. Press Ok and finish

All 11 comments

@awsaunier Can you provide the stack trace of CLI install? Also, check the global node_modules if it's installed or not?

I included a txt file of the stack. I didn't want to include it in here due to its long length.
Stack.txt
I don't know how to check Install for the node_modules is installed or not but I did do a search on my c: and I did find a node_modules folder was in C:\Program Files\nodejs\node_modules.

I have the same issue.

For Windows 10 users only

You can not install ng from the command line with a non administrator account
And there is no sudo. Only runas which runs as the administrator with the administrator profile.
The UAC does not kick in and ask you to provide admin permissions as when you run an installer.
So the ng binary will be located in the Administrator npm folder after installing using the runas feature.

Take a look at the folder "C:\Users\Administrator\AppData\Roaming\npm" and see if you can spot ng.
If you can then add "C:\Users\Administrator\AppData\Roaming\npm" to your path.

There is something called sudo for windows ( https://sourceforge.net/projects/sudowin/ )
It runs with elevated permissions, while preserving your profiling settings.
I haven't tried it. Use at own risk.

edited

I looked at my Admin account and you were right, it was installed there but I tried to use the 'ng' command on the admin account and it still does not work and gives me the same error. Is there a way to redirect that to a standard user account? In the past I was able to do all my development on a standard user account. Also I don't quite understand what you mean by.

If you can then add "C:\Users\Administrator\AppData\Roaming\npm" to your path.

I some further investigation and I upgraded my user account to admin and reinstalled angular cli and it now works. I was able to downgrade my account to a standard user and it still works. I don't know if this is still an windows issue related to what @MrRhino said and if this can be solved by an update to the cli. The thing that is puzzling me is that I was able to use the cli and everything fine a month ago and now having this issue. I am glad I can continue to code and I thank everyone that has help.

Is there a way to redirect that to a standard user account?

No.

If you can then add "C:\Users\Administrator\AppData\Roaming\npm" to your path.

I mean if you have ng in the above mentioned path, then add it to your current user path.

I some further investigation and I upgraded my user account to admin and reinstalled angular cli and it now works. I was able to downgrade my account to a standard user and it still works.

That is also a solution. But it still requires that you have administrator permissions.

The thing that is puzzling me is that I was able to use the cli and everything fine a month ago and now having this issue

Maybe Microsoft tightened their User Account Control

Personally i would add the administrator path "C:\Users\Administrator\AppData\Roaming\npm" to my current user path along with your current user path "C:\Users\\AppData\Roaming\npm".
That way all global modules will be available to you, even when you are required to install via. the administrator account.

Personally i would add the administrator path

What do you mean by add and where should I add the path?

  1. Hit the Windows button ( cmd on Mac ) and write "Environment"

2.

Select the option that says "Environment variables for your account" ( or similar in your own language )

  1. Select Path

  2. 4.

Select New and add "C:\Users\Administrator\AppData\Roaming\npm"

  1. Press Ok and finish

Thanks to @MrRhino for the advice and solution steps.

I'd just like to add that it is possible to install (to the best of my knowledge) to install Angular CLI on non-admin accounts. The missing bit seems to have been that the npm path was not part of the environment path, and thus global npm binaries could not be found.

At last find the solution for ng command is not working issue ,Find the solution below http://itechiesol.blogspot.com/2017/07/angular-cli-ng-command-is-not-working.html

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

_This action has been performed automatically by a bot._

Was this page helpful?
0 / 5 - 0 ratings

Related issues

JanStureNielsen picture JanStureNielsen  路  3Comments

hareeshav picture hareeshav  路  3Comments

NCC1701M picture NCC1701M  路  3Comments

daBishMan picture daBishMan  路  3Comments

jmurphzyo picture jmurphzyo  路  3Comments