355

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.

5
  • Can you run Get-ExecutionPolicy and provide the output? Additionally can you run to C:\Users\< username >\AppData\Roaming\npm and open the properties for ng.ps1, to see if there is a tick box which states "blocked", if so untick this.
    – Jacob
    Commented Sep 21, 2019 at 0:31
  • 4
    I think the best way is removing ng.ps1 when I did everything has worked again Commented Sep 21, 2019 at 11:32
  • 2
    @TheFabio Actually May I will never know, after deleting ng.ps1 everything was going in perfect way. Commented Nov 5, 2019 at 18:04
  • My Execution policy was not the issue but how I sent the arguments. If you are in the same boat, check out Executing Angular Serve From Powershell With Parameters Fail
    – ΩmegaMan
    Commented Jun 14, 2021 at 16:11
  • @AmirMakram Sir, this question is not related to javascript language, so please don't add the javascript tag.
    – Mina
    Commented Feb 15, 2023 at 21:20

11 Answers 11

892

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\

9
  • 163
    FYI clearing the cache was not necessary for me. Commented Nov 1, 2019 at 13:59
  • 6
    Great, but why? Is it left over from a previous Angular installation and no longer being called correctly? Why does it no longer work?
    – Patrick
    Commented Nov 20, 2019 at 4:55
  • 2
    Actually, I don't know. I don't even found any mention for this file anywhere so I thought that file really not necessary, so I just delete it Commented Nov 20, 2019 at 13:22
  • I have the "ng.ps1" (and "ng.cmd" and "ng", and "node_modules" folder) in C:\Users[username]\AppData\Roaming\npm folder. They were (re)created 2 days ago when I run ng update (I checked the modified date). After that update (current 8.3.21, previous: 8.3.xx) the ng stop to work with Powershell. Deleting it (renamed) solved the problem. No cache cleaning is needed but in VS Code you need to kill and reopen the Terminal. Maybe Angular introduced the "ng" command directly as a powershell script-let but that resulted in this common permission problem ?!
    – Alex 75
    Commented Dec 23, 2019 at 0:24
  • 8
    For anybody who wonders why this works: Windows by default blocks running unsigned powershell scripts because of security concerns. What is weird is why angular team keeps that script while it's really default behaviour for it to break Angular CLI and systems with unsigned script execution enabled are a minority. Removing this powershell script just stops Powershell from trying to execute .ps1 file and fall back to old cmd script, that also works, but was never restricted by Microsoft. Commented Feb 9, 2022 at 20:02
679

I solved my problem by running below command

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser

10
  • 1
    for more infor ... go.microsoft.com/fwlink/?LinkID=135170 Commented Feb 11, 2020 at 19:05
  • 16
    This should be the correct answer for new installs.
    – Chris
    Commented Apr 1, 2020 at 12:06
  • 1
    This seems to be right but quite unreliable.
    – Yogurtu
    Commented Jun 3, 2020 at 4:33
  • 2
    after this comment i enter 'a' to apply to All Policies. Thank You! Commented Jun 22, 2020 at 18:43
  • 2
    This fails in some enterprise environments where we are unable to set these perms. Commented Sep 3, 2020 at 14:23
42

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
1
  • Why do I specifically need to do this, when other folks does not have the same issue than me with the same version?
    – Yogurtu
    Commented Nov 9, 2021 at 15:49
13

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/

0
4

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/

1
  • It is worth remembering that after applying the command, the operation of the 'ng' command was immediate, I didn't even need to raise the application's permissions (VSCode) as an administrator. Commented Jul 13, 2023 at 4:30
4

This error happens due to a security measure that won't let scripts be executed on your system without you having approved it.

Solution:-

  1. Open Windows PowerShell

  2. execute this command

    set-ExecutionPolicy RemoteSigned -Scope CurrentUser

2

This error happens due to a security measure that won't let scripts be executed on your system without you having approved it.

I've also solved my problem by executing this command: Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser

This video helped me to fix this issue: https://www.youtube.com/watch?v=a--z7ZV1BqM

You can also try this. Hopefully will resolve your issue as well.

enter image description here

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
0

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

It won't then run the ps1 version of ng

-1

remove

ng.ps1 from the directory C:\Users%username%\AppData\Roaming\npm\

is not worked for me.

you can try open power shell blue screen then write

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser

this works well..

-5

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

3
  • 11
    Welcome to SO, complete your answer by providing the commands that do the works Commented Nov 4, 2019 at 7:23
  • 1
    This is a pretty bad advice as it opens the door to run any PowerShell script on your system.
    – 1nternetz
    Commented Jun 15, 2021 at 10:20
  • 2
    As stated in a previous answer Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser is a better way to go as it is less prone to open your system to running a malicious script. RemoteSigned 1) The script has to be signed by a trusted publisher. 2) The scope is set to the current user instead of the default which is LocalMachine. See Microsoft's documentation for additional details. learn.microsoft.com/en-us/powershell/module/…
    – 1nternetz
    Commented Oct 4, 2021 at 13:03

Not the answer you're looking for? Browse other questions tagged or ask your own question.