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
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.
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"
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!
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.
After changing the path you have to restart powershell. You do not need to restart your computer.
I was using npm (5.5.1) updating it to latest version solved my problem.