the term 'ng' is not recognized as the nam

2019-03-11 16:43发布

Today, while working through some basic AngularJS Intro, I ran into a problem. I opened PowerShell to get going on the project. NPM worked.

I was able to install the Angular using

npm install -g @angular/cli

Anytime I tried to run ng I would get

the term 'ng' is not recognized as the name of a cmdlet

9条回答
女痞
2楼-- · 2019-03-11 16:48

Instead of giving "ng serve" command in the Visual Studio code terminal, open angular app path in the command prompt(Run as Administrator).

Then give "ng serve" command.

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

It works for me.

查看更多
够拽才男人
3楼-- · 2019-03-11 16:57

Installing angular cli globally solved my problem.

npm install -g @angular/cli
查看更多
爱情/是我丢掉的垃圾
4楼-- · 2019-03-11 17:01

If your project name contain '-'. Remove it and try. This can cause problem in running 'ng'.

查看更多
别忘想泡老子
5楼-- · 2019-03-11 17:05

You can also make sure you run the Command Prompt - or whatever terminal you use - As Administrator. I am using Visual Studio Code and the ng serve command gives me that exact error when not running VS Code as admin.

查看更多
Rolldiameter
6楼-- · 2019-03-11 17:07

First setup Node.js, then go to your project folder with the command prompt such as D:\project and then run this command:

npm install -g @angular/cli

Now run ng command. This work for me.

查看更多
倾城 Initia
7楼-- · 2019-03-11 17:07

In the "Environment Variables"

In the "System variables" section

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

查看更多
登录 后发表回答