git 在 Windows 中安装 Angular 后 - ng 未被识别为内部或外部命令
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/47095241/
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
After installing Angular in windows - ng is not recognized as an internal or external command
提问by Raghul Rajendran
I try to install Angular but after installing i got this error
我尝试安装 Angular,但安装后出现此错误
ng is not recognized as an internal or external command,operable file or batch file
ng 不是内部或外部命令、可操作文件或批处理文件
I installed node,npm and git I gived below comment for installing Angular.I installed after installing i give ng-v comment i found this error.
我安装了 node、npm 和 git 我在下面给出了安装 Angular 的评论。我在安装后安装了我给出了 ng-v 评论我发现了这个错误。
npm install -g @angular/cli
npm install -g @angular/cli
采纳答案by Sathish Kotha
Add your node js path ex: " C:\Users\DELL\AppData\Roaming\npm" to System Variable source :follow this link
将您的节点 js 路径例如:“C:\Users\DELL\AppData\Roaming\npm”添加到系统变量源:按照此链接
回答by Nausheen Khan
Execute below command:-
执行以下命令:-
npm uninstall -g angular-cli
npm卸载 -g angular-cli
npm uninstall --save-dev angular-cli
npm 卸载 --save-dev angular-cli
npm cache clean
npm 缓存清理
npm install -g @angular/cli@latest
npm install -g @angular/cli@latest
Try out it for me it worked
为我试一试它有效
回答by Pramod Mali
回答by Abhishek Prakash
I personally never install angular-cli globally. What I do is -
我个人从不全局安装 angular-cli。我要做的是——
- Create a .bin folder some where in your workspace
- Use npm
npm install @angular/cli
- Come back to your root of workspace
- Create an angular app using -
.\path to .bin\node_modules\.bin\ng new new-app
- 在工作区的某个位置创建一个 .bin 文件夹
- 使用 npm
npm install @angular/cli
- 回到你工作空间的根目录
- 使用 - 创建一个有角度的应用程序
.\path to .bin\node_modules\.bin\ng new new-app
And you will be good to go.
你会很高兴去的。
回答by RandallTo
Spent days on this. Had 2 different machines and one worked like a charm the other I ended up uninstalling VS2017, NodeJs to start clean. I would install Nodejs without VS installed. Reinstall NodeJS then angular/cli and no NG recognized using NodeJS command prompt or any other command prompt. On NPM get it said it was installed in path "c:\ProgramData\Microsoft\VisualStudio\MDA..taco-toolset.." which made no sense since VS was completely gone.
The solution:
In c:\Users\YouUserName.nmprc file persisted after uninstalling Nodejs. Delete this file and reinstalled NodeJS then Angular/cli and all was good.
花了几天的时间。有 2 台不同的机器,其中一台工作得很好,另一台我最终卸载了 VS2017、NodeJs 以开始清理。我会在没有安装 VS 的情况下安装 Nodejs。重新安装 NodeJS,然后使用 NodeJS 命令提示符或任何其他命令提示符重新安装 angular/cli 并且没有识别出 NG。在 NPM 上,它说它安装在路径“c:\ProgramData\Microsoft\VisualStudio\MDA..taco-toolset..”中,因为 VS 完全消失了。
解决办法:在c:\Users\YouUserName.nmprc文件中卸载Nodejs后依然存在。删除此文件并重新安装 NodeJS,然后重新安装 Angular/cli,一切都很好。
I think this maybe a result of installing VS2017 with node project types. Not sure but it was one big mess which google lead to no solutions.
我认为这可能是使用节点项目类型安装 VS2017 的结果。不确定,但谷歌导致没有解决方案是一个大混乱。
回答by alytvynov
Try to run with sudo.
install your node and npm globally
尝试使用 sudo 运行。
全局安装您的节点和 npm
回答by Ajantha Bandara
Open a new terminal and try again. Sometimes after installing the package, this error message appears if you use the same window.
打开一个新终端并重试。有时在安装软件包后,如果您使用相同的窗口,则会出现此错误消息。
If not add it to environment variables.
如果没有将其添加到环境变量中。
回答by MazBeye
In my case, I was using VSCodeand WSL.
就我而言,我使用的是VSCode和WSL。
I was trying to generate a service from VSCode's Angular Schematics and got the same issue.
我试图从 VSCode 的 Angular Schematics 生成一个服务,但遇到了同样的问题。
Meanwhile, the path "./node_modules/.bin/ng" was actually there since the beginning while generating the project from angular cli. It's also included on the devDependencies
section in package.jsonafter generating an angular project.
同时,从 angular cli 生成项目时,路径“./node_modules/.bin/ng”实际上从一开始就存在。生成 angular 项目后,它也包含devDependencies
在package.json 中的部分中。
However, it seems that it needs sudo or special permission to invoke the ng
command from that particular directory. While, there's no way we can override the command from VSCode.
但是,似乎需要 sudo 或特殊权限才能ng
从该特定目录调用命令。但是,我们无法覆盖 VSCode 中的命令。
On the other hand, I also had @angular/cli
installed globally.
另一方面,我也@angular/cli
安装了全局。
Uninstalling the project's (local) @angular/cli should do the trick, by using this command:
使用以下命令卸载项目的(本地)@angular/cli 应该可以解决问题:
npm uninstall -D @angular/cli
npm uninstall -D @angular/cli
Therefore, VSCode's angular schematics (or any command that needs it) will try to use the global @angular/cli
that you've installed beforehand.
因此,VSCode 的 angular 原理图(或任何需要它的命令)将尝试使用@angular/cli
您事先安装的全局变量。
In case you haven't install it, then install it using:
如果您还没有安装它,请使用以下命令安装它:
npm install -g @angular/cli
.
npm install -g @angular/cli
.
That should do the trick.
这应该够了吧。