15

I've been happily using vscode/angular/node/npm for years without issue. Suddenly in the last hour or so without explicitly changing anything I'm getting the following error.

What are the most likely causes for the execute permissions, that were previously there, to suddenly be lost?

I hate having to say this in advance but to those that cannot comprehend I'm not asking about how to fix the error. I'm asking why my permissions were wiped causing it to appear.

Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.

Try the new cross-platform PowerShell https://aka.ms/pscore6

PS C:\Users\d> cd C:\source\my-WebApp
PS C:\source\my-WebApp> ng serve
ng : File C:\Users\d\AppData\Roaming\npm\ng.ps1 cannot be loaded. The file
C:\Users\d\AppData\Roaming\npm\ng.ps1 is not digitally signed. You cannot run this script on the current system.
For more information about running scripts and setting execution policy, see about_Execution_Policies at
https:/go.microsoft.com/fwlink/?LinkID=135170.
At line:1 char:1
+ ng serve
+ ~~
    + CategoryInfo          : SecurityError: (:) [], PSSecurityException
    + FullyQualifiedErrorId : UnauthorizedAccess
PS C:\source\my-WebApp>

Obviously this is the fix: PS C:\source\my-WebApp> Get-ExecutionPolicy -list

        Scope ExecutionPolicy
        ----- ---------------
MachinePolicy       Undefined
   UserPolicy       Undefined
      Process       Undefined
  CurrentUser       Undefined
 LocalMachine       AllSigned


PS C:\source\my-WebApp> set-ExecutionPolicy RemoteSigned -Scope CurrentUse

Execution Policy Change
The execution policy helps protect you from scripts that you do not trust. Changing the execution policy might expose
you to the security risks described in the about_Execution_Policies help topic at
https:/go.microsoft.com/fwlink/?LinkID=135170. Do you want to change the execution policy?
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "N"): Y
PS C:\source\my-WebApp> Get-ExecutionPolicy -list

        Scope ExecutionPolicy
        ----- ---------------
MachinePolicy       Undefined
   UserPolicy       Undefined
      Process       Undefined
  CurrentUser    RemoteSigned
 LocalMachine       AllSigned
3

6 Answers 6

64

This happens as your system, power shell is not yet allowed to execute any executable scripts. This error is encountered mainly in Windows 10 when using VS Code IDE where Power Shell is selected as a command-line option by default.

You can fix this issue by execute the following CMD command in the same Powershell terminal

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser

You can read info from this.

Or otherwise, you can delete this file and run ng serve again. Good luck!

3
  • This doesn't answer the question
    – m12lrpv
    Commented Jul 5, 2022 at 22:06
  • Do you need to run this command only once or everytime you get the error message?
    – Tassisto
    Commented Jan 7 at 20:01
  • @m12lrpv This exactly answers the question for me. I believe it should be the accepted answer.
    – Stewart
    Commented Mar 13 at 21:23
1

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

0

In Windows, when you try opening "New Terminal" from Terminal option in VS Code, PowerShell opens by default. The simplest option would be to just click on the drop-down button beside the tab written "PowerShell" on the top right side of the new window and choose "Command Prompt". Then you can proceed to open/serve your Angular project using "ng serve" command.

1
  • Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
    – Community Bot
    Commented Oct 31, 2023 at 23:51
0

I use the following if I'm trying to run it in a local powershell prompt. This will allow you to execute any of your scripts, but keep in mind this opens up the keys to the kingdom so I close the prompt when I'm finished.

powershell -Sta -ExecutionPolicy unrestricted

0

The best solution is to fix this error is that delete the ng.ps1 from your 'C' drive from the npm folder and then try to create component, definitely it will work.

-1

powershell Get-ExecutionPolicy -list , then set-ExecutionPolicy RemoteSigned -Scope CurrentUse work for me

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