Why powershell does not run Angular commands?

JavascriptAngularPowershellAngular Cli

Javascript Problem Overview


I have started to learn Angular but I note that powershell in Windows gives me an error whenever I make an angular command like:

ng new new-app

or

ng serve

this is the error what I got:

ng : File C:\Users\< username >\AppData\Roaming\npm\ng.ps1 cannot be loaded because 
running scripts is disabled on this system. For more information, see 
about_Execution_Policies at https:/go.microsoft.com/fwlink/?LinkID=135170.
At line:1 char:1
+ ng serve
+ ~~
    + CategoryInfo          : SecurityError: (:) [], PSSecurityException
    + FullyQualifiedErrorId : UnauthorizedAccess

P.S. I try these commands in cmd and it works.

Javascript Solutions


Solution 1 - Javascript

Remove ng.ps1 from the directory C:\Users\%username%\AppData\Roaming\npm\ then try clearing the npm cache at C:\Users\%username%\AppData\Roaming\npm-cache\

Solution 2 - Javascript

I solved my problem by running below command

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser

Solution 3 - Javascript

> script1.ps1 cannot be loaded because running scripts is disabled on > this system. For more information, see about_Execution_Policies at > http://go.microsoft.com/fwlink/?LinkID=135170

This error happens due to a security measure which won't let scripts be executed on your system without you having approved of it. You can do so by opening up a powershell with administrative rights (search for powershell in the main menu and select Run as administrator from the context menu) and entering:

set-executionpolicy remotesigned

Solution 4 - Javascript

Step 1

First, you have to need to open the command prompt and run this command.

set-ExecutionPolicy RemoteSigned -Scope CurrentUser

Step 2

Now you have to run the second command on your system. This command is:

Get-ExecutionPolicy

Step 3

To view their policy, you need to run this command in your command prompt:

Get-ExecutionPolicy -list

> https://www.c-sharpcorner.com/article/how-to-fix-ps1-can-not-be-loaded-because-running-scripts-is-disabled-on-this-sys/

Solution 5 - Javascript

open windows powershell, run as administrater and SetExecution policy as Unrestricted then it will work.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionAmir MakramView Question on Stackoverflow
Solution 1 - JavascriptAmir MakramView Answer on Stackoverflow
Solution 2 - JavascriptStanley MohlalaView Answer on Stackoverflow
Solution 3 - JavascriptHozaifaView Answer on Stackoverflow
Solution 4 - Javascriptmahsa kView Answer on Stackoverflow
Solution 5 - JavascriptPalla VishalView Answer on Stackoverflow