user11352561
user11352561

Reputation: 2647

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

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

Upvotes: 51

Views: 113859

Answers (11)

Chamith Mendis
Chamith Mendis

Reputation: 303

If you are using windows, try running the command on Command Prompt. It Worked for me

Upvotes: 0

Marco Mascellani
Marco Mascellani

Reputation: 83

If you're in Windows, easy solution is adding to "ng" the correct file extension:

ng g s auth/services/login (ERROR!)

ng.cmd g s auth/services/login (OK!)

Upvotes: 1

Krishna
Krishna

Reputation: 473

I had similar issue while running in Windows Powershell. But same command works in traditional command prompt. Might help for someone.

I did no change in windows policy. Below is default setting in my system.

PS C:\Users\krishna> Get-ExecutionPolicy -list

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

Upvotes: 0

Takesha  Kaluarachchi
Takesha Kaluarachchi

Reputation: 439

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.

Upvotes: 5

Rakesh Singh Balhara
Rakesh Singh Balhara

Reputation: 410

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.

Upvotes: 1

Mounir bkr
Mounir bkr

Reputation: 1665

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

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

Upvotes: 1

Akash Sahu
Akash Sahu

Reputation: 17

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)

Upvotes: -1

gbroz dev
gbroz dev

Reputation: 519

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

Upvotes: 51

Sujeewa K. Abeysinghe
Sujeewa K. Abeysinghe

Reputation: 347

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

Upvotes: 5

Gaganam Krishna
Gaganam Krishna

Reputation: 151

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

Upvotes: 0

Drashti Dobariya
Drashti Dobariya

Reputation: 3006

This issue occurs due to undefined Execution policy.

Try this command in Powershell:

Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Unrestricted

Upvotes: 153

Related Questions