10
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?

5

7 Answers 7

10

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

5

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

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
1

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.

2
  • 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. Commented Nov 4, 2019 at 13:26
  • This solution worked for me on my windows 10 machine, except the location of cache was C:\Users\<username>\AppData\Local\npm-cache.
    – NCCSBIM071
    Commented Feb 24 at 16:16
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!

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.

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.

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

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