Amir Makram
Amir Makram

Reputation: 12988

Why powershell does not run Angular commands?

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.

Upvotes: 365

Views: 503632

Answers (7)

Simon_Weaver
Simon_Weaver

Reputation: 145890

A quick workaround is to run the command from a .bat file

It won't then run the ps1 version of ng

Upvotes: 0

You can try Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser.

Important things to note when running this command:

  1. run ng from project folder
  2. check ng version
  3. check angular cli in properly install or you can reinstall by running npm install -g @angular/cli

Upvotes: 2

Sameera Peiris
Sameera Peiris

Reputation: 189

Step1: Get-ExecutionPolicy for your Machine using the below command

Get-ExecutionPolicy -List

Step2: Once your identity scope and execution policy, please run the below commands using the same.

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser

if above doesn't work, install the minimum node version angular required and run bellow command

npm install -g @angular/cli

if you want handle multiple node version use nvm as follows;

https://www.freecodecamp.org/news/node-version-manager-nvm-install-guide/

Upvotes: 6

mahsa k
mahsa k

Reputation: 655

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/

Upvotes: 17

Amir Makram
Amir Makram

Reputation: 12988

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\

Upvotes: 909

Stanley Mohlala
Stanley Mohlala

Reputation: 7531

I solved my problem by running below command

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser

Upvotes: 693

Hozaifa
Hozaifa

Reputation: 437

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

Upvotes: 42

Related Questions