ng: command not found

前端 未结 11 1417
伪装坚强ぢ
伪装坚强ぢ 2020-12-21 00:22

I am trying to run ng build in my project folder, but I get the following response:

bash: ng: command not found

Wha

相关标签:
11条回答
  • 2020-12-21 00:49

    In case others come here with this issue as I have, here is how I solved it system-wide on MacOS. Hope this helps.

    Verify node is installed:

    $ node -v
    v11.2.0
    

    Verify npm is installed:

    $ npm -v
    6.4.1
    

    Verify your npm global install file path is configured (known as prefix). Mine is under ~/.npm-packages:

    $ npm config ls -l | grep prefix
    prefix = "/Users/christiangroleau/.npm-packages"
    

    If not, you can place it into your ~/.npmrc file:

    echo prefix=~/.npm-packages >> ~/.npmrc
    

    Verify that your prefix path is listed in your system PATH:

    $ echo $PATH
    /Users/christiangroleau/.npm-packages/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
    

    If not, invoke the following:

    export PATH="$HOME/.npm-packages/bin:$PATH"
    

    Finally, you can reinstall angular-cli (in my case I needed to install it globally):

    $ npm install -g @angular/cli
    

    Verify installation:

    $ ng -v
    
    0 讨论(0)
  • 2020-12-21 00:50

    Based on your comments to other answers: This npm issue might be related to your problem, your npm installation might be outdated.

    First of check whether you use a recent version of node. Then update npm with npm i -g npm as the issue suggests (near bottom). Then if ng is still not found follow the update instructions of @angular/cli:

    npm uninstall -g @angular/cli
    npm cache verify
    # if npm version is < 5 then use 'npm cache clean'
    npm install -g @angular/cli@latest
    
    0 讨论(0)
  • 2020-12-21 00:51

    If you have installed the dependencies locally and need to refer those packages instead of global. use npx before the the command eg: npx ng build refers to the locally installed package. ng build refers to the global package.

    0 讨论(0)
  • 2020-12-21 00:58

    npm doesn't recognize ng command.

    Try this command:

    npm link @angular/cli

    to link npm and angular-cli.

    0 讨论(0)
  • 2020-12-21 00:58

    You need to install the Angular CLI globally. Run npm install -g @angular/cli

    0 讨论(0)
  • 2020-12-21 00:59

    For windows user: Just go to your windows environment setting and set user path as C:\Users\HP\AppData\Roaming\npm

    0 讨论(0)
提交回复
热议问题