Fix PowerShell Execution Policy Blocking npm Scripts
PowerShell is blocking the `npm.ps1` shim, so your `npm` command stops before your package script starts. The safest fix on a Windows developer machine is usually to set the execution policy for your user account to `RemoteSigned`, then try the command again in the same shell. If it still fails, the policy may be coming from a different shell or from machine-managed settings.
Symptom
npm : File C:\Program Files\nodejs\npm.ps1 cannot be loaded because running scripts is disabled on this system.This usually shows up in PowerShell on Windows when you run npm or npm run ... and PowerShell tries to launch the npm.ps1 shim instead of the underlying command.
Before you start
This applies to PowerShell on Windows, especially when Node.js and npm were installed in the usual way and npm resolves to the npm.ps1 shim.
You usually only need your normal user account. If your machine is managed and policy changes are locked down, you may need Administrator help to change a machine-level policy, but the user-scope fix does not require elevated privileges.
You do not need to restart Windows, and there is nothing to back up for this change. Before you change anything, check that you are actually in PowerShell and that npm fails there but not necessarily in another shell.
Questions people ask after they fix it
The reason PowerShell blocks npm is that it treats .ps1 files as scripts, not as plain executables. On Windows, npm installs a npm.ps1 wrapper so npm behaves like a normal command in PowerShell, but that wrapper still has to pass the execution policy check.
The safest fix is usually RemoteSigned at the CurrentUser scope. That lets locally created scripts run for your account without turning off PowerShell protections for the whole machine. It does not remove script checks entirely, and it is narrower than lowering the policy system-wide.
If you use another shell, such as Command Prompt or Git Bash, npm may work there even if PowerShell blocks it. That does not change the PowerShell setting; it just avoids the .ps1 shim.
If the error comes back on a different terminal, a different user profile, or another machine, check whether a local policy, Group Policy, or an endpoint management tool is overriding your setting. On a managed device, the durable fix is often to have that policy adjusted centrally.
Fix 1: Set the policy for your user account
Do this in PowerShell for your own account. You do not need Administrator access for this step.
- Open PowerShell.
- Run this command:
Set-ExecutionPolicy -Scope CurrentUser RemoteSigned- If PowerShell asks for confirmation, accept it.
Expected result: the user-scope policy is changed to RemoteSigned. If that does not happen, the setting may be blocked by a machine policy, and you will need to check the policy list in the same shell.
If the command is rejected, or if the setting appears to change and then reverts, a higher-priority policy is probably overriding it.
Fix 2: Check whether a machine policy is overriding your setting
Do this in the same PowerShell session where npm fails. No restart is needed.
- Run this command:
Get-ExecutionPolicy -ListExpected result: you should see RemoteSigned under CurrentUser, and no stricter policy should be taking precedence for the shell you are using.
If MachinePolicy or UserPolicy shows a stricter value, your user setting will not win. That usually means Group Policy or another management tool is controlling execution policy on the device.
If CurrentUser is RemoteSigned but npm still fails, you are probably in a different shell, terminal profile, or account than the one where you changed the setting.
Verify it worked
Run the same npm command again in the same PowerShell window, or open a new PowerShell window and try it there.
Expected result: npm should start the package script instead of stopping at the script-blocked execution policy error. If the command now runs, the npm.ps1 shim is being allowed under your current policy.
If npm still fails, compare Get-ExecutionPolicy -List in the failing shell with the shell where it worked. A mismatch usually means the terminal, user account, or machine policy is different.
Conclusion
If `RemoteSigned` fixed it, keep using PowerShell normally and continue in that shell. If the block returns, check `Get-ExecutionPolicy -List` in the exact terminal where `npm` fails, then bring that output to your admin if the machine policy is managed.
Frequently Asked Questions
Is changing the execution policy safe?
`RemoteSigned` at the `CurrentUser` scope is the usual low-risk fix for developers. It is less permissive than disabling policy checks, and it keeps a distinction between local scripts and downloaded ones.
Why does `npm` need `npm.ps1` on Windows?
PowerShell uses `.ps1` scripts for command shims, so the Node.js installer provides one. That wrapper lets `npm` behave like a normal command in PowerShell.
Can I fix this without changing the policy?
Yes, sometimes. You can use Command Prompt, Git Bash, or another shell instead of PowerShell, which avoids the PowerShell script policy. That does not change the underlying PowerShell setting.
Why did it work once and then fail again?
A new terminal session may be using a different policy, or a machine setting may be overriding your user setting. On managed devices, Group Policy can reset or block the change.