【问题标题】:angular-cli ng error after installing on a MAC在 MAC 上安装后出现 angular-cling 错误
【发布时间】:2018-03-05 08:17:43
【问题描述】:

我正在尝试在我的 Mac Book Pro 上安装 MEAN 堆栈。 安装 node 和 angular-cli 后我一直收到错误。

运行命令 'ng help, 或 ng -v' 时出现错误: "帮助 -bash: ng: command not found".

这是我的规格: 节点-v v6.11.3 npm -v 3.10.10 MAC Sierria 10.12.6

我已经在论坛中尝试了几个步骤,并且多次卸载并重新安装了 node 和 npm。

另外,我尝试从 BREW 安装和卸载。但我一直收到同样的错误。

是否有在 MAC 上安装 MEAN 堆栈的正确方法?专门针对我在使用 angular-cli 时遇到的问题?

另外,我已经根据这个站点设置了我的 npm 文件夹的权限:https://docs.npmjs.com/getting-started/fixing-npm-permissions

【问题讨论】:

    标签: node.js angular angular-cli mean-stack


    【解决方案1】:

    您似乎没有全局安装@angular/cli。使用-g 标志全局安装:

    npm i @angular/cli -g
    

    检查你的全局安装包运行:

    npm ls -depth 0 -g
    

    如果您的列表很长,您可以使用grep 缩小范围:

    npm ls -depth 0 -g | grep angular
    

    确保您在此处列出了 Angular CLI。

    我个人更喜欢在每个项目本地安装 Angular CLI 并通过 node_modules/.bin 访问它:

    node_modules/.bin/ng -v
    

    【讨论】:

    • 顺便说一句,您在 Angular CLI 中使用的是哪个 MEAN 堆栈? mean.io?
    • 我想我没有意识到有多种选择。我从这个网站的步骤开始:forum.freecodecamp.org/t/…
    • 运行 'npm ls -depth 0 -g' 我得到 '@angular/cli@1.4.3 npm@5.4.2'
    • 奇怪,你在本地有角度 CLI。您也可以通过执行:PATH=$PATH:`npm root -g`/@angular/cli/bin 将其添加到您的 $PATH。 npm root -g(带反引号)应该返回全局节点模块位置,只需确保其中有“@angular/cli/bin”路径
    【解决方案2】:

    在这里找到这个:https://github.com/angular/angular-cli/issues/5021 为我工作。

    npm install -g @angular/cli
    
    Make sure the ng path is correct
        cd ~/npm-global/bin
        ls and make sure ng exists
    
    create .bashrc file on your home directory
        touch ~/.bashrc
        vim ~/.bashrc
    
    Add ng as alias
        press a (enables edit mode) then type in the following
        alias ng="~/npm-global/bin/ng"
        press esc (to get out of edit mode) then :wq (in vim will save)
    
    Temporarily Update .bashrc reference
    Your terminal wont take bash updates until a restart but the following command will let you use the updates during the terminal session:
        source ~/.bashrc
    
    Check that ng works
        ng --version
    

    【讨论】:

    • 看来你可能需要在每次启动终端时输入 source ~/.bashrc
    【解决方案3】:

    npm install -g @angular/cli

    https://github.com/angular/angular-cli/blob/master/README.md

    如果您的节点有问题,您可能需要nvm

    【讨论】:

      猜你喜欢
      • 2016-11-05
      • 1970-01-01
      • 2017-06-12
      • 2018-08-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-12-03
      • 2017-01-21
      相关资源
      最近更新 更多