ng: command not found

前端 未结 11 1423
伪装坚强ぢ
伪装坚强ぢ 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 01:00

    I had the same error, but I am running Windows 10 and none of answers worked for me. These were the steps I took to get it resolved:

    Verify Angular is installed by running the following command in Git BASH:

    npm run ng -v
    

    Install Angular if it is not already installed by running the following command:

    npm install -g @angular/cli@latest
    

    Get the npm PATH by running the following command:

    npm config get prefix
    

    Open up advanced system settings by either using the shortcut windows+pause (aka break) and clicking on Advanced System Settings or by using Cortana to search for the phrase System Environment Variables

    Click on Environment Variables to bring up the environment variables dialog.

    Select the row for the user variable Path and click on Edit

    Click on New and enter the path returned from earlier. Then click on OK and OK again to close out of the Environment Variables dialog.

    Restart Git BASH and test that it working by running the command:

    ng -v
    
    0 讨论(0)
  • 2020-12-21 01:03

    In my case, I have just copied a whole repository (including its node_modules) from a Windows machine to a Linux machine, and running npx ng XXX failed with the following error:

    npx: installed 1 in 1.677s
    command not found: ng
    

    The main issue was, of course, line breaks. Using the dos2unix package, I was able to overcome it:

    sudo apt install -y dos2unix
    dos2unix node_modules/.bin/ng
    chmod +x node_modules/.bin/ng
    
    0 讨论(0)
  • 2020-12-21 01:05

    Try this:

    node_modules/.bin/ng build
    

    Or better, add a blank "ng": "ng"line into your scripts key in package.json and run this:

    `npm run ng build`
    

    You could also add this to your path:

    export PATH=$PATH:./node_modules/bin
    

    Which would let you run any binary in any npm project you might have.

    0 讨论(0)
  • 2020-12-21 01:06

    This was a pain to figure out, so here is my solution

    1. npm install -g @angular/cli

    2. Make sure the ng path is correct
        * cd ~/npm-global/bin
        * ls and make sure ng exists here!
    3. create .bashrc or .bash_profile or .bash_everything file on your home directory with:
        * touch ~/.bash_profile 
    open this file with text editor or Sublime or vi or etc.
        * open -e .bash_profile 
    4. Add ng as alias
        * writing this:
       alias ng="~/npm-global/bin/ng"  or   alias ng="MyFullPAThere/npm-global/bin/ng"
        * save file and close text editor. 
    5. Temporarily Update . bash_profile 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 ~/.bash_profile
    6. Check that ng works
        * ng --version
    

    Hope that helps someone!

    0 讨论(0)
  • 2020-12-21 01:08

    try to uninstall and clean the cache.

    npm uninstall -g @angular/cli
    npm cache clean
    npm install -g @angular/cli
    
    0 讨论(0)
提交回复
热议问题