我正在尝试使用“npm install @ angular/cli -g”设置Angular 2。
安装后,我看到的唯一警告是UNMET PEER DEPENDENCY rxjs@^5.0.1,然后我安装并重新安装“npm install @ angular/cli -g”
无论我做什么,或者我使用n设置了哪个版本的Node,在尝试使用“ng”命令时,我都会不断收到以下消息:
zsh:找不到命令:ng
我一直在环顾四周,还没有找到解决方案。
有没有人碰到这个,有什么建议吗?
更新:
看来这不是与 Angular/cli有关的问题。
现在,当我尝试在运行良好的现有项目上运行“Grunt”和“Ionic”命令时,会收到相同的消息。
zsh:找不到命令: ionic
zsh:找不到命令:grunt
最佳答案
最有可能的是,全局模块的安装目录不在$PATH
中,因此对于您的 shell 来说是未知的。
要解决此问题,我们可以为全局node_modules创建一个新目录,配置npm
以使用它,然后将该目录添加到您的$PATH
中。
# create a new directory where npm will install packages
$ mkdir ~/.node_modules
# set npm "prefix" config to that directory
$ npm config set prefix '~/.node_modules'
# append a line to your .zshrc instructing it to include that directory in your $PATH, making the executables known to the shell
$ echo 'export PATH=~/.node_modules/bin:$PATH' >> ~/.zshrc
# update current shell with new path (not needed for new sessions)
$ source ~/.zshrc
然后,首先重新安装最新的npm(
npm i -g npm
),然后重新安装所需的全局软件包(npm i -g @angular/cli
)。有关
PATH
的更多信息,请参见以下定义:http://www.linfo.org/path_env_var.html关于node.js - 在Mac上无法安装@ angular/cli的安装,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/42323442/