node.js 术语“ng”未被识别为 cmdlet 的名称

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/44958847/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 18:20:29  来源:igfitidea点击:

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

node.jsangularpowershellnpmangular-cli

提问by Wauna

Today, while working through some basic AngularJS Intro, I ran into a problem.

今天,在学习一些基本的 AngularJS Intro 时,我遇到了一个问题。

I opened PowerShell to get going on the project. NPM worked.

我打开 PowerShell 以开始该项目。NPM 起作用了。

I was able to install the Angular using:

我能够使用以下方法安装 Angular:

npm install -g @angular/cli

Anytime I tried to run ng, I would get:

每当我尝试运行 ng 时,我都会得到:

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

回答by jonrsharpe

The first path in the path variable needs to be the NPM path. Opening the Node.js command prompt I found that the ng command worked there. I dug into the shortcut and found that it references a command to ensure the first Path variable is NPM. To Fix:

path 变量中的第一个路径需要是 NPM 路径。打开 Node.js 命令提示符,我发现 ng 命令在那里工作。我深入研究了快捷方式,发现它引用了一个命令来确保第一个 Path 变量是 NPM。修理:

  1. Right Clicked on My Computer (windows)
  2. Selected Advanced System Settings
  3. Clicked "Environment Variables"
  4. Under "Path" variable, made the FIRST value listed %AppData%\npm
  1. 右键单击我的电脑(Windows)
  2. 选定的高级系统设置
  3. 点击“环境变量”
  4. 在“路径”变量下,列出第一个值 %AppData%\npm

Once I did that I was able to close powershell and reopen and all worked.

一旦我这样做了,我就能够关闭powershell并重新打开并且一切正常。

回答by Ahmadreza Farrokhnejad

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

首先设置 Node.js,然后使用命令提示符(例如 D:\project)转到您的项目文件夹,然后运行以下命令:

npm install -g @angular/cli

Now run ng command. This work for me.

现在运行 ng 命令。这对我有用。

回答by A. Morel

In the "Environment Variables"

在“环境变量”中

In the "System variables" section

在“系统变量”部分

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

在“路径”变量中和之前"C:\Program Files (x86)\nodejs\"添加 =>"%AppData%\npm"

回答by KRIPA SHANKAR JHA

Solution Worked For me :

解决方案对我有用:

Add a path to your environment Variable

添加环境变量的路径

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

as well as your bin folder of the angular file [present their itself]

以及角度文件的 bin 文件夹[展示它们自己]

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

and then run ng -vit will pop up angular cli gui in your Command prompt. Note After running npm i -g @angular/clido restart your command prompt and check if it works otherwise clean cache and repeats the above steps.

然后运行 ng -v它会在你的命令提示符中弹出 angular cli gui。注意运行后npm i -g @angular/cli重新启动命令提示符并检查它是否有效,否则清理缓存并重复上述步骤。

回答by Rut Shah

Installing angular cli globally solved my problem.

全局安装 angular cli 解决了我的问题。

npm install -g @angular/cli

回答by shambhu yadav

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

如果您的项目名称包含“-”。删除它并尝试。这可能会导致运行 'ng' 出现问题。

回答by AleHulk

Open Edit the system environment variables

打开编辑系统环境变量

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

在“Path”和“PS ​​Module Path”变量中添加“%AppData%\npm”

Run Visual Code as Administrator

以管理员身份运行 Visual Code

It works for me!

这个对我有用!

回答by PrafulPravin

You just need to close the visual studio code and restart again. But to get the ng command work in vs code, you need to first compile the project with cmd in administrator mode.

您只需要关闭 Visual Studio 代码并重新启动。但是要让 ng 命令在 vs code 中工作,你需要先在管理员模式下用 cmd 编译项目。

I was also facing the same problem. But this method resolved it.

我也面临同样的问题。但是这个方法解决了。

回答by Rayan Albouni

Changing the policy to Unrestricted worked for me:

将政策更改为 Unrestricted 对我有用:

Set-ExecutionPolicy Unrestricted -Scope CurrentUser

回答by vidhya c

I resolved by following the below steps

我按照以下步骤解决了

1.Right click on command Prompt 2.Run as administrator 3.type npm install -g @angular/cli

1.右键单击命令提示符 2.以管理员身份运行 3.键入 npm install -g @angular/cli