node.js - 为 @angular/cli 安装在 Mac 上不工作

标签 node.js angular npm

我正在尝试使用“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:找不到命令:咕噜声

最佳答案

安装全局模块的目录很可能不在您的 $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 - 为 @angular/cli 安装在 Mac 上不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42323442/

相关文章:

node.js - NodeJS : Opening new tab instead of default user browser

node.js - simple-peer 包无法按预期工作

angular - mat-datepicker 添加 touchUI 条件

node.js - 向 glitch.me 服务器发出跨域请求

Angular Firestore 集合快照更改

Angular 2,使用 ngZone.runOutsideAngular 和 requestAnimationFrame 循环

javascript - 禁用 create-react-app 的 SKIP_PREFLIGHT_CHECK 有缺点吗?

node.js - npm 发布带有 css 和字体的组件

javascript - 选择过滤器的下拉列表

javascript - 如何在发送初始 Web 服务器响应之前检测服务器端浏览器是否支持 Javascript?