运行windows 7 Professional 32bit。

我试着在normal或admin下运行npm install -g angular-cli。

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

我做错了什么?


当前回答

关闭CMD并再次以管理员权限打开或重新启动系统。

其他回答

在我的情况下,我做了以下步骤。

所有程序-> 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"]

}

现在我在Visual Studio Code终端窗口中输入ng -v,它工作了。

I was having the same issue when tried with the syntax "ng new " and solved that simply by updating the existing node version from 5.x.x to 8.x.x. After successful updation of node, the syntax worked perfectly for me. Please update the existing version of node. As it is clearly mentioned in angular documentation that these commands require the node version >= 6.9.x. For reference please check https://angular.io/guide/quickstart. It clearly states "Verify that you are running at least node 6.9.x and npm 3.x.x by running node -v and npm -v in a terminal/console window. Older versions produce errors, but newer versions are fine".

通过命令

npm install -g @angular/cli@latest

它工作得很好,我现在能够运行ng命令了。

我使用的是win10,只是为了解决这个问题。 在cmd中输入下面的代码:

NPM配置获取前缀

然后复制粘贴你从顶部得到的路径到你的计算机环境变量——>用户变量盒子——> path——> edit——C:\Program Files\nodejs\ node_global,你的路径可能不同。

点击确定并重新打开cmd窗口,输入ng版本,然后它就工作了!干杯!

我也面临着同样的问题,但已经解决了。在我的最终原因是我安装节点和CLI使用其他用户配置文件,现在我从其他用户登录运行ng命令。由于节点和cli安装使用其他用户登录节点在C:\Users\<用户名>\AppData\漫游此路径上找不到任何东西,这就是为什么我得到这个错误。

我运行npm install -g @angular/cli命令并重启我的机器。一切都很正常。