ng: command not found while creating new project using angular-cli

后端 未结 30 2687
忘掉有多难
忘掉有多难 2020-11-28 23:42

Installed angular-cli globally using (npm install -g angular-cli) but when I\'m trying to create project using ng new my-project it is throwing err

相关标签:
30条回答
  • 2020-11-28 23:49

    According to npm, the angular-cli has been renamed to @angular/cli you can use the following syntax to install it.

    npm install -g @angular/cli
    
    0 讨论(0)
  • 2020-11-28 23:49

    In my case, it was happening when I restarted working on an adjacent tab. It was the npm which was not set. Please check the version of npm wither using

    npm -v

    or if you are having nvm then

    nvm list

    or

    nvm current

    I set it to 8.9.1 and then it started working again. I hope it helps.

    0 讨论(0)
  • 2020-11-28 23:53

    In my case, I was simply running the wrong node version.

    I had just previously installed a new node version to play around with Angular (2). At work we use 6.x so that is my default in nvm. After restarting the laptop ng stopped working simply because I was running node 6.x again. So for me it was simply a matter of using the version with which I was installing the Angular CLI:

    nvm use node // with the node alias pointing to the right version
    

    or

    nvm use v8.11.3 // if you happen to know the version
    

    Check your installed versions and aliases with

    nvm list 
    
    0 讨论(0)
  • 2020-11-28 23:55

    Same problem here running Windows 10 x64 / NodeJS 6.9.1 / npm 3.10.9.
    After installation of Angular CLI via npm:

    'ng' command cannot be found

    Do the following:

    1. Uninstalled npm with npm uninstall -g npm
    2. Uninstalled NodeJS via control panel / programs and features
    3. Downloaded and ran 'old' NodeJS installer release 6.5.0 from https://nodejs.org/download/release/v6.5.0/ (node-v6.5.0-x64.msi).
    4. After NodeJS 6.5.0 installation completed, open powershell and npm install -g angular-cli
    5. Grab quick coffee
    6. After installation completed, ng worked OK.

    HTH

    0 讨论(0)
  • 2020-11-28 23:55

    Do you install the node js package? https://nodejs.org/en/ Regards

    0 讨论(0)
  • 2020-11-28 23:55

    For me (on MacOSX) I had to do:

    nvm install stable
    npm install -g angular-cli
    

    This installed ng into:

    /usr/local/lib/node_modules/@angular/cli/bin/ng
    

    But npm did not put a link to ng into

    /usr/local/bin/
    

    Which was why it was not part of the %PATH and therefore available from the command line except via an absolute address.

    So I used the following the create a link to ng:

    sudo ln -sf /usr/local/lib/node_modules/\@angular/cli/bin/ng /usr/local/bin/ng
    
    0 讨论(0)
提交回复
热议问题