node.js 在 Windows 中创建新项目时未找到 ng 命令 angular-cli
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/40858759/
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
ng command not found angular-cli when create new project in windows
提问by Md.Shahjalal
i am successfully install node.js and angularjs2 using this command. node version is
我使用此命令成功安装了 node.js 和 angularjs2。节点版本是
node version v6.9.1
npm install -g angular-cli
and the installation path is that
安装路径是
C:\Users\Arobil\AppData\Roaming\npm\node_modules\angular-cli\bin
which are include
其中包括
system->advanced system setting->Environment variable->path
but the problem is that when i create new project using angular its
但问题是当我使用 angular 创建新项目时
D:>ng new app 'ng' is not recognized as an internal or external command, operable program or batch file.
D:>ng new app 'ng' 不是内部或外部命令,也不是可运行的程序或批处理文件。
Am i missing anything?
我错过了什么吗?
回答by manish kumar
- Uninstall Everything npm uninstall -g angular-cli
- 卸载一切 npm uninstall -g angular-cli
npm uninstall -g @angular/cli
npm cache clean
- Re-install
- 重新安装
npm install -g @angular/cli
Now have a look in your global NPM folder, it should be something like "/Users//.npm-global/bin/". In here you should see your angular CLI files. To test if everything works, try typing:
现在查看您的全局 NPM 文件夹,它应该类似于“/Users//.npm-global/bin/”。在这里你应该看到你的 angular CLI 文件。要测试是否一切正常,请尝试键入:
ng -v
If this does not work, then try manually adding an alias that mappings ng to your ng folder, like so:
如果这不起作用,请尝试手动添加将 ng 映射到 ng 文件夹的别名,如下所示:
alias ng="/Users/<username>/.npm-global/bin/ng"
I've also had issues where I have not had 'sudo' permissions. To get around this you can change your global path. To do this you can do something like this within your ~/.bash_profile :
我也遇到过没有“sudo”权限的问题。要解决此问题,您可以更改全局路径。为此,您可以在 ~/.bash_profile 中执行以下操作:
export PATH="$HOME/.npm-packages/bin:$PATH"
Taken from here
取自这里
回答by Goldy
You just need to add path in Your Environment Variable. To do this, follow these steps. go to my computer properties >> advanced system settings >> environment variable >> add new variable and assign path to your NPM.
您只需要在您的环境变量中添加路径。为此,请按照下列步骤操作。转到我的计算机属性 >> 高级系统设置 >> 环境变量 >> 添加新变量并为您的 NPM 分配路径。
For Example my NPM path:-
例如我的 NPM 路径:-
path : D:\Users\goldy.b\AppData\Roaming\npm
路径:D:\Users\goldy.b\AppData\Roaming\npm
回答by user3444999
I am using Mac and this worked for me.
我正在使用 Mac,这对我有用。
alias ng="/Users/Batman/.npm-packages/lib/node_modules/@angular/cli/bin/ng"
别名 ng="/Users/Batman/.npm-packages/lib/node_modules/@angular/cli/bin/ng"
回答by Asad Shakeel
You need to link your angular cli with npm using
您需要使用 npm 链接您的 angular cli
npm link @angular/cli
npm link @angular/cli
That worked like a charm
这就像一个魅力
回答by Sen
After making an entry to the path variable for C:/Users/{userName}/Appdata/Roaming/npm folder, run the following command npm config get prefixand check whether the output is consistent with the above one i.e. C:/Users/{userName}/Appdata/Roaming/npm.
进入C:/Users/{userName}/Appdata/Roaming/npm文件夹的路径变量后,运行如下命令 npm config get prefix,检查输出是否与上述一致,即C:/Users/ {userName}/Appdata/Roaming/npm.
If the path is not same, make sure that you run the command npm config set prefix "APPDATA\Roaming\npm". Now once you install the angular/cli using -g all corresponding packages will be downloaded in this folder and you will be able to run ng commands from any directory of your machine.
如果路径不同,请确保您运行命令npm config set prefix "APPDATA\Roaming\npm"。现在,一旦您使用 -g 安装了 angular/cli,所有相应的包都将下载到此文件夹中,您将能够从机器的任何目录运行 ng 命令。
回答by Skyravi
I had the same problem. Just change your project name and it will work.
我有同样的问题。只需更改您的项目名称,它就会起作用。

