20

I have an Angular project and if I want to start the project with 'ng serve' it is opening the ng file from

C:\Users{user}\AppData\Roaming\npm\node_modules\@angular\cli\bin

Also, I can start the project with 'npm start'.

7
  • which version you are using? for angular 2+ ng new YourProjectName to create a project and ng serve to run. Commented Jun 22, 2018 at 11:25
  • if you are able to run others commands such as ng new app, ng serve -o should work as well, what version of angular cli are you using ? Commented Jun 22, 2018 at 11:27
  • doesn't work any command with ng. The project is from github and I can only run with npm start. Commented Jun 22, 2018 at 11:44
  • you probably missing npm cli Commented Jun 22, 2018 at 12:18
  • 'npm' work. 'ng' just open the ng file from that path. It not execute anything Commented Jun 22, 2018 at 12:26

9 Answers 9

28

Remove path "C:\Users{user}\AppData\Roaming\npm\node_modules@angular\cli\bin" from Environment variable - path. It worked for me.

Sign up to request clarification or add additional context in comments.

2 Comments

When the path is removed NG is not recognized, when the path is added, it tries to open NG.JS file in angular-cli binaries path
Finally I can run ng command, your solution work for me.
10

The problem was that I use ng in powershell. In cmd work..

4 Comments

o...m...g. This has taken 1 hour for me. Thanks for this comment. Why the hell isnt it working inside the powershell?
Similar problem here... I am unable to make it work in Visual Studio Code but it works fine in a gitbash terminal
Also works for me. This is the right solution in my case.
Why would this be the case?
6

I had a similar problem where typing ng in terminal open ng.js in vscode so my fix to it in Environment Variable remove any angular path in system variable and in user variable add this path C:\Users\Here\AppData\Roaming\npm don't forget to add your system name in the (Here)

2 Comments

When I open 'Edit the System Environment Variables' (<Windows key>, type 'environment'), I have details for two kinds of Environment Variables. The top one is User Variables, and the bottom is System Variables. I've clicked Edit on the item called 'Path' in my User Variables and added the file path, as per your solution. I never had anything similar in my System Variables. It still doesn't work for me. Is this as you described?
C:\Users\Zero\AppData\Roaming\npm did you change Zero with your Pc name hope you resolve your issue
2

You have configured wrong environment variable path.

Path should be: C:\Users\{UserName}\AppData\Roaming\npm

NOTE: Verify ng.cmd file should be there in C:\Users\{UserName}\AppData\Roaming\npm. If not please reinstall anglular cli.

Comments

1

Here the quick way to solve the problem.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..

Comments

1

Make sure you have angular cli installed globally. This worked for me:

npm install -g @angular/cli

Comments

0

In my case, i was encountered an error related to 'ng serve' it is opening the ng file. To resolve this issue, you need to upgrade to a newer version of Node.js

Comments

0

Make sure to add %USERPROFILE%\AppData\Roaming\npm to the user variables in environment variable.
Then, close all your command window and then try again.

Comments

0

In my case, ExecutionPolicy was added in my Windows machine, so I reverted by using the below command in PowerShell

Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Undefined

check ExecutionPolicy through Get-ExecutionPolicy -List

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.