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

后端 未结 30 821
灰色年华
灰色年华 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:14

    You can also make sure you run the Command Prompt - or whatever terminal you use - As Administrator. I am using Visual Studio Code and the ng serve command gives me that exact error when not running VS Code as admin.

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

    This powershell script worked to add the correct setting to my Environment Variable "Path" ( As a per-user setting. ) It adds: %AppData%\npm ...and then restart the command line that uses "ng"

       $existingPath = [System.Environment]::GetEnvironmentVariable("Path","User")      
       write-host "existing PATH variable is $existingPath"                                          
       $newPath = "%AppData%\npm;$existingPath"                                          
       write-host "new      PATH will be     $newPath"                                               
    
       # update here                                                                                      
       [System.Environment]::SetEnvironmentVariable("Path", $newPath, "User")           
    
       $finalPath = [System.Environment]::GetEnvironmentVariable("Path","User")         
       write-host "final    PATH variable is $finalPath"                                             
    
    0 讨论(0)
  • 2020-12-01 01:16

    Open Edit the system environment variables

    In the "Path" and "PS Module Path" variable add "%AppData%\npm"

    Run Visual Code as Administrator

    It works for me!

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

    Solution Worked For me :

    Add a path to your environment Variable

    C:\Users\YourPcName\AppData\Roaming\npm
    

    as well as your bin folder of the angular file [present their itself]

    C:\Users\YoutPcName\AppData\Roaming\npm\node_modules\angular-cli\bin
    

    and then run ng -v it will pop up angular cli gui in your Command prompt. Note After running npm i -g @angular/cli do restart your command prompt and check if it works otherwise clean cache and repeats the above steps.

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

    After changing the path you have to restart powershell. You do not need to restart your computer.

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

    I was using npm (5.5.1) updating it to latest version solved my problem.

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