8
ng : File C:\Users\Lenovo\AppData\Roaming\npm\ng.ps1 cannot be loaded. The file C:\Users\Lenovo\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

while giving ng serve showing this error..how to overcome it?

MikaelF
  • 3,518
  • 4
  • 20
  • 33
Rohan
  • 81
  • 1
  • 2
  • Rohan please try to use ng serve in a standard cmd. The Powershell is very different releated to the standard cmd. – Jacopo Sciampi Nov 04 '19 at 14:52
  • standard cmd means – Rohan Nov 04 '19 at 15:57
  • press the win logo key and type "cmd" then hit enter. the CMD shell will open. That's the standard cmd. The *.ps1 files runs into the powerShell, a more complex shell that, I believe, isn't supported by the cli. – Jacopo Sciampi Nov 05 '19 at 09:17
  • Try the following answer: https://stackoverflow.com/a/58044573/12932907 It solved the problem for me. – Schnikles Jun 03 '22 at 16:17
  • Does this answer your question? [why am I suddenly getting: ng : File C:\Users\d\AppData\Roaming\npm\ng.ps1 cannot be loaded](https://stackoverflow.com/questions/72863930/why-am-i-suddenly-getting-ng-file-c-users-d-appdata-roaming-npm-ng-ps1-canno) – starball Jun 23 '23 at 19:23

7 Answers7

8

Run the following command from the same terminal or command prompt and re-run the ng command to check if it works on your machine.

The Command is=> Set-ExecutionPolicy RemoteSigned -Scope CurrentUser

4

You need to set Scope execution policy of the CurrentUser to RemoteSigned with the command below:

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
Mwiza
  • 7,780
  • 3
  • 46
  • 42
1

Resolution

This issue means your Machine is preventing you from running of script files. Implementation of these policies occurs on Windows platforms, including Windows client or Windows Server machine. The PowerShell execution policies are as follows:

Formatting and configuration files (.ps1xml), module script files (.psm1), and PowerShell profiles (.ps1).

Steps to resolve the issue

To change the PowerShell execution policy on your Windows computer, use the below commands:

Step1: Windows PowerShell and execute the bellow 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

All set, now type ng serve, and you are ready to go. Happy Coding!

André Mendonça
  • 658
  • 8
  • 13
0

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\

For me this worked, just had the same problem.

Author of this fix is from THIS post.

  • Also did npm update and then npm audit fix, but that might not be needed for you, I just did it as I thought I needed that anyway. – CreativeOne Nov 04 '19 at 13:26
0

You can try npm start as an alternate for ng serve

for a permanent solution, you would like to take a look into this answer.

Appu Mistri
  • 768
  • 8
  • 26
0

For me this issue was caused by a fresh install of VS Code having powershell as the default terminal instead of CMD. Changing the default to CMD and executing it from there solved this problem for me.

Cdtj3
  • 1
0
  1. Open up Windows Powershell as Administrator
  2. Run the following command: set-executionpolicy remotesigned
  3. You should be able to now run commands in the Visual Studio Code terminal for Angular and Node.js.

Credit

Ram
  • 1,225
  • 2
  • 24
  • 48