316

运行 windows 7 专业版 32 位。

我尝试npm install -g angular-cli在正常或管理员下运行。 2016-06-23_14h46_40

我还尝试将其添加到 PATH: 下的环境变量(C:\Users\Administrator\AppData\Roaming\npm\node_modules\angular-cli\bin\ng)中,但也没有成功。
2016-06-23_14h56_48

我究竟做错了什么?

4

51 回答 51

385

我按照图解决了这个问题:

在cmd中运行

 npm install -g @angular/cli

接着

(在Windows 10中打开)控制面板\所有控制面板项\系统或如图

步骤1:

在此处输入图像描述

第2步 :

在此处输入图像描述

第三步:

在此处输入图像描述

第4步:

在此处输入图像描述

step5:添加缺失的ng路径

在此处输入图像描述

这是您需要添加的新环境变量:C:\Users\PK\AppData\Roaming\npm\node_modules\@angular\cli\bin

最后,重新启动所有打开的命令提示符并重试。

于 2017-09-06T02:53:02.100 回答
293

对我来说,它适用于:

npm run ng <command>
于 2017-03-29T13:09:27.970 回答
131

添加C:\Users\DELL\AppData\Roaming\npm到系统变量Path对我有用。请找到“npm”的适当文件路径

另外,检查您是否已将angular-cli\bin路径添加到路径变量。

于 2016-11-11T14:21:03.023 回答
84

我正在使用WIN 10,只是为了解决这个问题。在cmd中输入以下代码:

npm 配置获取前缀

并将您从顶部获取的路径复制并粘贴到您的计算机环境变量中-->用户变量框-->路径-->编辑--C:\Program Files\nodejs\node_global,您的路径可能不同。

单击确定并重新打开您的 cmd 窗口,输入ng version,然后它就可以工作了!干杯!

于 2017-06-19T04:19:01.883 回答
49

只需打开您的命令提示符(以管理员身份运行)。确保node --v为 6.9.0 或更高版本,并且npm --v为 3.0.0 r 更高版本。

之后运行以下命令:

npm install -g @angular/cli

一旦安装了角度。您可以在路径中看到 angular cli 的条目

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

然后尝试 ng help。它会起作用的。

于 2017-06-28T13:48:54.263 回答
44

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.

于 2019-10-09T10:31:42.753 回答
20

With a command

npm install -g @angular/cli@latest

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

于 2018-04-05T10:07:10.320 回答
20

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.

于 2019-06-24T10:12:19.233 回答
18

几天前,在与其他全局模块遇到相同问题后,我通过添加:

环境表 -> 系统变量 -> 路径:

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

请注意,它后面不能有任何空格;

原来是我的问题。

于 2016-07-01T09:47:05.393 回答
12

与其使用内置的命令提示符,不如使用 NodeJS 安装版本的命令提示符开始。然后它将完美地工作而没有任何问题。在此处输入图像描述

于 2017-09-27T12:00:18.400 回答
12

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

于 2018-02-24T16:21:12.433 回答
11

如果您在执行上述步骤后仍出现错误。然后在下面尝试。

因为它是一个节点脚本。到目前为止,我正在使用以下选项进行创建。

节点 C:\Users\Administrator\AppData\Roaming\npm\node_modules\angular-cli\bin\ng 版本

可能需要符号链接。没有进一步研究。

进一步研究:将路径设置为:%PATH%;C:\Users\Administrator\AppData\Roaming\npm;

在 Windows 中,npm.cmd 文件位于上述路径中。如果设置了上述环境变量,则可以执行为 ng version ng init

于 2016-08-19T07:56:00.833 回答
9

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.

于 2021-05-19T10:34:46.030 回答
7
  1. 打开cmd并输入npm install -g @angular/cli

  2. 在环境变量中,添加用户变量或系统变量“路径”值=C:\Users\your-user\.npm-packages\node_modules\.bin

  3. 在命令中:c:\>cd your-new-project-path

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

    或者ng all-ng-commands

于 2017-08-06T07:25:15.320 回答
6

关闭 cmd 并使用管理员权限再次打开它或重新启动您的系统。

于 2016-06-26T19:54:09.643 回答
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

于 2019-03-14T03:04:39.247 回答
6

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

于 2020-03-20T11:14:03.427 回答
5

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

于 2018-05-28T14:45:10.263 回答
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

于 2019-09-26T00:58:42.003 回答
4

这个几乎对我有用,但我不得不使用: %USERPROFILE%\AppData\Roaming\npm 。在环境变量.../系统变量/路径

然后,当我执行 CMD:"ng -v" 时,我得到了 angular cli 的正确响应。

于 2017-05-24T20:31:18.007 回答
3

我在使用 npm v3.10.8 运行的 64 位 Windows 7 上遇到了同样的问题。

  1. 我按照建议添加了路径:( C:\Users.....(您的用户名)\AppData\Roaming\npm\node_modules\angular-cli\bin\ng)并卸载了 angular-cli。
  2. npm cache clean在此之后,我按照此处的提示清除了 npm 缓存https://blogs.msdn.microsoft.com/matt-harrington/2012/02/23/how-to-fix-node-js-npm-permission-problems/ . 这保证没有剩菜。
  3. 重新安装了angular-cli,npm install -g angular-cli瞧。

    希望这可能有用!
于 2017-02-09T19:32:59.523 回答
3

就我而言,我做了以下步骤。

所有程序-> Node JS-> 右键单击​​ Node.js 命令提示符并选择属性,然后从下面末尾复制的目标字符串中选择

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

我启动了 Visual Studio Code 并打开了下面的文件

C:\Users\gochinta\AppData\Roaming\Code\User\settings.json并在下面给出

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

}

现在我输入ng -v了我的 Visual Studio Code Terminal 窗口并且它工作了。

于 2017-04-17T22:37:07.787 回答
3

我在尝试使用语法“ng new”时遇到了同样的问题,只需通过将现有节点版本从 5.xx 更新到 8.xx 即可解决该问题。成功更新节点后,该语法对我来说非常有效。请更新节点的现有版本。正如 Angular 文档中明确提到的那样,这些命令需要节点版本 >= 6.9.x。如需参考,请查看https://angular.io/guide/quickstart。它明确指出“通过在终端/控制台窗口中运行 node -v 和 npm -v 来验证您至少运行 node 6.9.x 和 npm 3.xx。旧版本会产生错误,但新版本很好”。

于 2017-06-22T11:17:46.707 回答
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

于 2017-10-11T09:32:19.463 回答
2
于 2017-10-08T15:01:52.320 回答
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.

于 2017-12-26T15:15:51.637 回答
2

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.

于 2018-06-07T05:15:49.200 回答
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.

于 2018-10-09T04:51:12.160 回答
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.

于 2018-10-22T11:22:55.823 回答
1

我遇到了同样的问题,即 Visual Studio Code 无法在其内置终端中运行任何 ng 命令。

我将 %AppData%\npm 添加到 Windows 10 的路径中,并且不必重新启动,只需关闭并重新打开 VS Code 并没有看到它。

于 2017-08-15T19:46:03.847 回答
1

安装x32 版本的 nodejs而不是x64 版本(即使在 64 位 Windows 机器上)。

于 2017-08-28T09:44:56.837 回答
1

我也在关注这个问题,所以我尝试了这个命令,它运行良好。使用这个命令: npm run ng

于 2017-09-08T12:13:55.873 回答
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.

于 2017-12-15T06:25:39.380 回答
1

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

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

于 2018-05-30T14:54:43.263 回答
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.

于 2019-03-06T09:38:22.420 回答
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.)

于 2020-05-15T09:45:23.470 回答
1

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\
于 2022-01-11T12:09:32.907 回答
0

设置路径=%path%;C:\Users\\AppData\Roaming\npm

于 2017-05-24T09:43:58.083 回答
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

于 2017-12-12T13:18:30.633 回答
0

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

于 2018-02-07T08:16:07.160 回答
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")
}
于 2018-05-04T07:44:26.593 回答
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

于 2018-07-04T22:18:56.790 回答
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.

于 2019-03-23T08:22:14.020 回答
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.

于 2019-09-08T17:54:42.217 回答
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.

于 2019-09-22T07:34:43.837 回答
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.

于 2019-10-07T17:17:39.687 回答
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.

于 2021-05-12T10:21:35.613 回答
0

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.

于 2021-11-29T15:35:58.980 回答
-1

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

于 2018-02-04T19:24:08.207 回答
-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.

于 2018-06-05T14:25:27.760 回答
-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.

于 2018-07-30T09:32:41.197 回答