我尝试运行npm install -g angular-cli
我还尝试将其添加到PATH下的环境变量:(C:\ Users \ Administrator \ AppData \ Roaming \ npm \ node_modules \ angular-cli \ bin \ ng),但也没有成功。
答案 0 :(得分:64)
You can also try:
> npm run ng <command>
答案 1 :(得分:47)
使用NodeJS命令提示符而不是Windows命令,NodeJs命令提示符将识别ng。
答案 2 :(得分:31)
您不应将ng.cmd
添加到PATH中。只有一个javascript文件,您无法在终端中使用。
您需要%AppData%\Roaming\npm
,可能位于psexec @servers.txt -u <username> cmd /c "powershell -noninteractive -file C:\temp\script.ps1"
。
确保此路径包含在PATH变量中。
答案 3 :(得分:20)
我在Windows7上遇到了同样的问题。我解决了,设置了正确的路径。
首先在系统上找到ng.cmd文件。通常会在:
E:\Users\<USERNAME>\AppData\Roaming\npm
在此位置设置PATH
。
关闭现有命令窗口并打开新的命令窗口
类型
ng -v
还请记住使用-g命令安装angular。
npm install -g @angular/cli
答案 4 :(得分:10)
您应该添加ng.cmd所在的路径。默认情况下,它应位于 C:\ Users \ user \ AppData \ Roaming \ npm
注意:此处“用户”可能因您的电脑用户名而异!
答案 5 :(得分:7)
我遇到了同样的问题,现在发现了一个有效的解决方案。 成功安装node和angular CLI后,请执行以下步骤。
打开C:\usr\local
并复制角度CLI位于您计算机上的路径或路径。
现在在Windows中打开环境变量,并在以下位置添加复制的路径:
Advanced > Environment Variable > User Variables and System Variables
如下图:
全部,现在打开cmd并尝试使用任何&#39; ng&#39;命令:
答案 6 :(得分:4)
确保正确设置环境变量。
control panel-> system->advanced system settings-> select advanced Tab->
click on environment variables
并确保在以下路径中可用
`C:\Users\username\AppData\Roaming\npm`
此处用户名将根据用户
进行更改
仍然如果它不工作你的环境变量没有得到反映 所以请重启你的机器它会正常工作
如果你仍然面临问题 你的角度cli安装不正确
请运行以下命令以重新安装
npm uninstall -g @angular/cli
npm cache clean or npm cache clean --force
npm install -g @angular/cli@latest
答案 7 :(得分:3)
只需在先前的答案中添加一些信息,如果您使用的是Windows 7或更高版本,请开始搜索 Node.js命令提示符,您将直接看到该应用。单击它,然后通过使用该命令提示符输入角度来开始工作。
答案 8 :(得分:2)
此答案基于@YuSolution https://stackoverflow.com/a/44622211/4567504的以下答案。
就我而言,安装MySQL会更改我的路径变量,即使在全局范围内多次重新安装@ angular / cli之后,我也无法解决该问题。
解决方案:
在命令提示符下,运行以下命令
npm config get prefix
路径将返回
C:\ Users {{您的用户名}} \ AppData \ Roaming \ npm
复制此路径,然后转到ControlPanel>“系统和安全性”>“系统”,单击“高级系统设置”,转到“高级”选项卡,然后选择环境变量按钮,如
现在在用户变量框中,单击路径行并进行编辑,然后在变量值框中粘贴复制的路径。
重新启动命令提示符,它将起作用
答案 9 :(得分:2)
无需卸载angular / cli。
C:\Users\yourusername\AppData\Roaming\npm
ng-v
并应能正常工作答案 10 :(得分:1)
对我有用的是我丢失了文件
.npmrc
位于
下C:\Users\username
该文件应包含
prefix=$(APPDATA)\npm
我的环境路径也指向我的管理员用户
答案 11 :(得分:1)
npm更新为我解决了这个问题
答案 12 :(得分:1)
我已经在下面的步骤及其正常工作中进行了尝试:-
答案 13 :(得分:1)
您无需设置任何路径。请按照以下步骤解决问题-
第1步转到
C:\Users\user\AppData\Roaming and delete npm, npm-update and npm-cache folder
第2步运行
npm install -g @angular/cli@yourangularversion again.
答案 14 :(得分:0)
我刚安装了cli cli并解决了我的问题,只需运行:
npm install -g @angular/cli
答案 15 :(得分:0)
这个问题也困扰着我,然后我发现可能的情况来重现这个问题
当我在管理员中运行窗口时,它运行正常 ng ,但是当我像其他用户一样在第二个空间中运行它时,我遇到了这个问题。
所以如果我想运行我的角度应用程序,那么我需要运行此命令
正在运行的npm运行ng服务 但是当我使用-host npm run ng server --host IP 运行命令时,由于某些错误,它无法正常工作
所以我找到了一些可能的解决方案 1.转到 appdata ,然后 user \ admin \ AppData \ Roaming \ npm文件夹,然后复制此路径,但是如果使用其他用户帐户 user \ newuser \ AppData \漫游\ npm文件夹,您可以从其他用户(即admin用户帐户)复制此npm文件夹。 如果您不想复制此文件夹,请复制**** user \ admin \ AppData \ Roaming \ npm folder ****文件夹的路径,然后打开环境变量设置并将此路径添加到路径变量名称中>
在系统路径变量中输入此路径,而不是用户变量 C:\ Users \ admin \ AppData \ Roaming \ npm
答案 16 :(得分:0)
注意:系统重启后,您可能会丢失值。
您还可以在Windows 10中添加没有管理员权限的系统环境变量。
现在不要重新启动,关闭任何打开的cmd或powershell ,重新打开cmd并通过 ng version 命令进行测试(如果看到)确认工作正常。
希望这会有所帮助
答案 17 :(得分:0)
简答:
只需安装最新版本的 nodejs,然后重新启动系统。
更多说明:
至少据我所知,它与您系统中的环境变量有关,您可以像其他人在当前线程中讨论的那样更改系统中的路径变量,但解决此问题的最简单方法是安装 nodejs!< /p>