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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 12:57:56  来源:igfitidea点击:

After installing Angular in windows - ng is not recognized as an internal or external command

javascriptnode.jsgitangular

提问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

Add Following path

添加以下路径

Just add path to global npm location:

只需添加全局 npm 位置的路径:

C:\Users\username\AppData\Roaming\npm

C:\用户\用户名\AppData\Roaming\npm

The above directory contains "ng" command enter image description here

上述目录包含“ng”命令 在此处输入图片说明

回答by Abhishek Prakash

I personally never install angular-cli globally. What I do is -

我个人从不全局安装 angular-cli。我要做的是——

  1. Create a .bin folder some where in your workspace
  2. Use npm npm install @angular/cli
  3. Come back to your root of workspace
  4. Create an angular app using - .\path to .bin\node_modules\.bin\ng new new-app
  1. 在工作区的某个位置创建一个 .bin 文件夹
  2. 使用 npm npm install @angular/cli
  3. 回到你工作空间的根目录
  4. 使用 - 创建一个有角度的应用程序 .\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.

就我而言,我使用的是VSCodeWSL

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 devDependenciessection in package.jsonafter generating an angular project.

同时,从 angular cli 生成项目时,路径“./node_modules/.bin/ng”实际上从一开始就存在。生成 angular 项目后,它也包含devDependenciespackage.json 中的部分中。

However, it seems that it needs sudo or special permission to invoke the ngcommand 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/cliinstalled 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/clithat 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.

这应该够了吧。