⚠️ Fixing “npm.ps1 cannot be loaded because running scripts is disabled” in PowerShell

| Application program | 114 Reads

When working on a Node.js project in Windows using PowerShell, you may encounter this error:

npm : File C:\Program Files\nodejs\npm.ps1 cannot be loaded because running scripts is disabled on this system.

This happens because PowerShell's execution policy restricts running .ps1 scripts — including the auto-generated npm.ps1 — for security reasons.

Let’s walk through why this happens and how you can fix it safely and quickly.


🔍 Why Does This Error Occur?

When you run:

npm install

PowerShell looks for npm and finds npm.ps1 in your system path. If your execution policy is too strict (e.g., Restricted), it prevents PowerShell from running any .ps1 scripts — even trusted ones like npm.ps1.


✅ Solution 1: Bypass Execution Policy (Recommended for One-Time Use)

You can temporarily allow scripts in the current PowerShell session using:

Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass

Then run your command again:

npm install

This change only lasts while the current PowerShell window is open — it reverts when closed.


✅ Solution 2: Call npm.cmd Directly

PowerShell is trying to run the .ps1 version of npm. You can bypass the script policy entirely by invoking the .cmd file instead:

& "C:\Program Files\nodejs\npm.cmd" install

This works because .cmd files aren't affected by PowerShell's script execution restrictions.


⚙️ Optional: View Current Execution Policy

To see your current policy settings, run:

Get-ExecutionPolicy -List

If CurrentUser or LocalMachine is set to Restricted, you’ll likely encounter this issue often.


⚠️ Not Recommended: Permanently Lowering Policy

You can permanently allow local scripts by setting:

Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy RemoteSigned

However, this lowers security and is not advised unless you understand the risks.


🧭 Final Thoughts

For most developers, a temporary bypass (Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass) or using npm.cmd directly is the best option.

If you find yourself hitting this issue often and you're developing in PowerShell daily, consider adjusting the policy to RemoteSigned, but do so with caution.


💡 Tip: You can also switch to using CMD or Git Bash as your terminal, where these issues do not occur.

This article was last edited at