10

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
m12lrpv
  • 997
  • 2
  • 11
  • 18

4 Answers4

30

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!

Park Numb
  • 521
  • 3
  • 8
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

Your terminal is opened on powershell you need to switch to Command Prompt. on the right of the vs code terminal add another terminal pick the Command Prompt (node js) option.

this will execute all ng commands

Hezy Ziv
  • 3,652
  • 2
  • 14
  • 8
-1

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