运行windows 7 Professional 32bit。
我试着在normal或admin下运行npm install -g angular-cli。
我还尝试将它添加到PATH: (C:\Users\Administrator\AppData\Roaming\npm\node_modules\angular-cli\bin\ng)下的环境变量中,也没有成功。
我做错了什么?
运行windows 7 Professional 32bit。
我试着在normal或admin下运行npm install -g angular-cli。
我还尝试将它添加到PATH: (C:\Users\Administrator\AppData\Roaming\npm\node_modules\angular-cli\bin\ng)下的环境变量中,也没有成功。
我做错了什么?
当前回答
今天我也遇到了同样的问题,我走过了下面这条路—— (%USERPROFILE%\AppData\Roaming\npm),当我清除npm目录下的所有内容时,才知道有一些垃圾数据。现在当我运行(npm安装命令再次)。现在一切正常。
其他回答
如果您在执行上述步骤后仍然得到错误。然后试试下面的建议。
因为它是一个节点脚本。我现在使用下面的选项来创建。
\ users \Administrator\AppData\Roaming\npm\node_modules\angular-cli\bin\ng版本
可能需要符号链接。没有进一步研究。
进一步研究: C:\Users\Administrator\AppData\Roaming\npm;
在Windows中,npm。CMD文件在上述路径下。如果设置了上述环境变量,则可以执行为 ng版本 ng init
我有同样的问题,Visual Studio代码不能在它的内置终端中运行任何ng命令。
我添加了%AppData%\npm到Windows 10的路径中,并且不需要重新启动,只是关闭和重新打开VS Code,它看不到它。
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".
由于这个问题在一年后仍然被反复问到,我将在这里发布我的答案。
提示(仅在Windows上)是正确地安排path变量中的条目。
正如NPM wiki告诉我们的:
因为安装程序将C:\Program Files (x86)\nodejs放在你的PATH上的C:\Users\ AppData\Roaming\npm之前,所以它总是使用node安装的npm版本,而不是你使用npm -g install npm@<version>安装的npm版本。
所以你的路径变量看起来像这样:
…;C: \ < path-to-node-installation >; % appdata % \ npm;…
现在你有两种可能:
交换这两个元素,它看起来就像
…;%appdata%\npm;C:\<path-to-node-installation>;…
这将加载与npm一起安装的npm版本(而不是与node一起安装)和已安装的Angular CLI版本。
如果你(无论出于什么原因)喜欢使用npm版本和node绑定,将直接路径添加到你的全局Angualr CLI版本中。C:\Users\<username>\AppData\Roaming\npm\node_modules\@angular\cli;C:\<path-to-node-installation>;% AppData %\npm; 或者……;% appdata % \ npm \ node_modules \ @angular \ cli; C: \ < path-to-node-installation >; % appdata % \ npm;… 简写形式。
这对我来说很管用。
在我的情况下,我做了以下步骤。
所有程序-> 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,它工作了。