Angular - ng.ps1 cannot be loaded because running scripts is disabled on this system

Viewed 33713

In my Angular-12 Application, I tried to generate service using:

ng g s auth/services/login

but I got this error:

ng : File C:\Users\akweey\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 g s auth/services/login
+ ~~
+ CategoryInfo          : SecurityError: (:) [], PSSecurityException
+ FullyQualifiedErrorId : UnauthorizedAccess

When I checked the path: C:\Users\akweey\AppData\Roaming\npm\ng.ps1,

I only found ng but no ng.ps1

How do I get this resolved?

Thanks

8 Answers

This issue occurs due to undefined Execution policy.

Try this command in Powershell:

Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Unrestricted

Just delete this file. C:\Users\username\AppData\Roaming\npm\ng.ps1

execute this on powershell,

Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Unrestricted

for next, "Do you want to change the execution policy?" give "yes to all"

A
Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Unrestricted

Open PowerShell Termial and try to run the above command.

This worked for me.

(You might need to reopen the terminal)

enter image description here

I have installed the ng (angular in globally ) and trying to access in E:\ drive got above error, I executed the above given command, then now working fine for me.enter image description here

open the PowerShell with administrative rights. and run those commands:

  1. set-ExecutionPolicy RemoteSigned -Scope CurrentUser
  2. Get-ExecutionPolicy
  3. Get-ExecutionPolicy -list

This could be due to the current user having an undefined ExecutionPolicy.

In PowerShell as Administrator, you could try the following:

Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Unrestricted

Run above command on terminal. I was facing this issue on my intellij after upgrading the node and angular version.

Go to the path of your npm install

 C:\Users\{user_name}\AppData\Roaming\npm

and delete ng.ps1 file from location and recomplie the programme.

Related