The term 'ng' is not recognized as the name of a cmdlet

后端 未结 30 823
灰色年华
灰色年华 2020-12-01 00:24

Today, while working through some basic AngularJS Intro, I ran into a problem.

I opened PowerShell to get going on the project. NPM worked.

I was able to in

相关标签:
30条回答
  • 2020-12-01 01:08

    The problem is NOT the install of the NPM nor the path ! If you want to use the "ng" command you need to install the angular-cli. by running the following command

    npm install -g @angular/cli
    

    https://cli.angular.io/

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

    Even though the correct answers have been given. But all of these didn't work for me because:

    • My username didn't have the Administrator privileges and I couldn't update the environment variable like suggested in the answers.

    So for all of you who face the same issue as me here is what I did:

    Instead of ng serve

    I copy-pasted the complete location path of ng like the following and it worked. So the ng serve command became:

    C:\Users\MyUserName\AppData\Roaming\npm\ng.cmd serve

    0 讨论(0)
  • 2020-12-01 01:09

    All answers are about how to fix it, but the best is to download nodeJs and let the installer add to PATH variable.

    Version 12 and 13 are too new, so I had to download 11.15 https://nodejs.org/download/release/v11.15.0/

    0 讨论(0)
  • 2020-12-01 01:09

    Please also make sure that the node_modules folder also exists there in the project directory. If it is not there you will get a similar issue. so please run npm install as well.

    0 讨论(0)
  • 2020-12-01 01:11

    If your project name contain '-'. Remove it and try. This can cause problem in running 'ng'.

    0 讨论(0)
  • Instead of giving "ng serve" command in the Visual Studio code terminal, open angular app path in the command prompt(Run as Administrator).

    Then give "ng serve" command.

    Then open browser and go to the http://localhost:4200/

    It works for me.

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