ng:使用 angular-cli 创建新项目时找不到命令 [英] ng: command not found while creating new project using angular-cli

查看:45
本文介绍了ng:使用 angular-cli 创建新项目时找不到命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 (npm install -g angular-cli) 全局安装了 angular-cli,但是当我尝试使用 ng new my-project 创建项目时,它正在抛出错误:

Installed angular-cli globally using (npm install -g angular-cli) but when I'm trying to create project using ng new my-project it is throwing error:

ng:未找到命令

推荐答案

首先,angular-cli 已被弃用,并已替换为 @angular/cli.因此,如果您使用 npm uninstall angular-cli 卸载现有的 angular-cli,然后使用新名称 @angular/cli 重新安装软件包,您可能会遇到一些冲突.我在 Windows 7 上的故事是:

First, angular-cli is deprecated and has been replaced with @angular/cli. So if you uninstall your existing angular-cli with npm uninstall angular-cli, then reinstall the package with the new name @angular/cli you might get some conflicts. My story on Windows 7 is:

我已经安装了 angular-cli 并使用 npm install -g @angular/cli 重新安装,但是在对命令行工具进行一些配置更改后,我开始遇到 ng 命令未找到问题.我花了几个小时试图解决这个问题,但上述问题都没有单独奏效.我能够使用以下步骤修复它:

I had installed angular-cli and reinstalled using npm install -g @angular/cli, but after doing some config changes to command-line tools, I started getting the ng command not found issue. I spent several hours trying to fix this but none of the above issues alone worked. I was able to fix it using these steps:

安装 Rapid Environment Editor 并删除 node、npm、angular-cli 或@角度/cli.Node.js 将在您的 System 路径中,npm 和 angular 条目将在 User 路径中.

Install Rapid Environment Editor and remove any PATH entries for node, npm, angular-cli or @angular/cli. Node.js will be in your System path, npm and angular entries are in the User path.

卸载 node.js 并重新安装当前版本(对我来说是 6.11.1).再次运行 Rapid Environment Editor 并确保 node.js 和 npm 在您的系统或用户路径中.卸载任何现有的 ng 版本:

Uninstall node.js and reinstall the current version (for me 6.11.1). Run Rapid Environment Editor again and make sure node.js and npm are in your System or User path. Uninstall any existing ng versions with:

npm uninstall -g angular-cli

npm uninstall -g @angular/cli

npm cache clean

删除 C:\Users\%YOU%\AppData\Roaming\npm\node_modules\@angular 文件夹.

重启,然后,最后,运行:

Reboot, then, finally, run:

npm install -g @angular/cli

然后屏住呼吸跑起来:

ng -v

如果幸运的话,你会得到一些爱.以后每次运行 ng 命令时都要屏住呼吸,因为在 ng 运行良好后,找不到命令"神奇地重新出现了好几次,我以为问题已经解决了.

If you're lucky, you'll get some love. Hold your breath henceforward every time you run the ng command, because 'command not found' has magically reappeared for me several times after ng was running fine and I thought the problem was solved.

这篇关于ng:使用 angular-cli 创建新项目时找不到命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆