Reputation: 2647
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
Reputation: 303
If you are using windows, try running the command on Command Prompt. It Worked for me
Upvotes: 0
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
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
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
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
Reputation: 1665
open the PowerShell with administrative rights. and run those commands:
Upvotes: 1
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
Reputation: 519
Just delete this file. C:\Users\username\AppData\Roaming\npm\ng.ps1
Upvotes: 51
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
Reputation: 151
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.
Upvotes: 0
Reputation: 3006
This issue occurs due to undefined Execution policy.
Try this command in Powershell:
Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Unrestricted
Upvotes: 153