If you’re using PowerShell and encounter this error:
ng : File C:\Users\USER\AppData\Roaming\npm\ng.ps1 cannot be loaded because running scripts is disabled on this system.
It means that PowerShell’s execution policy is preventing scripts from running. Here’s the solution:
Steps to Fix the Error
Open PowerShell as Administrator Search for "PowerShell" in the Start menu, right-click, and select "Run as Administrator."
Change Execution Policy Run the following command to allow local scripts to run:
Set-ExecutionPolicy RemoteSigned -Scope CurrentUser
This sets the execution policy to
RemoteSigned
, which allows scripts created locally to run while requiring signed scripts from remote sources.Restart PowerShell Close the PowerShell window and reopen it to apply the changes.
Run Your Project Again Navigate to your project directory and execute:
ng serve
By adjusting the execution policy, you can resolve this issue and ensure PowerShell allows script execution for your Angular project.