Problem:
When running npm init -y
in PowerShell, you encounter:

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 is set to Restricted
, blocking script execution (including npm commands).
Solution:
1️⃣ Temporarily Bypass the Policy (For Current Session Only)
Set-ExecutionPolicy Bypass -Scope Process -Force
- Works only for the current PowerShell window.
- Safe, as it doesn’t permanently change system settings.
2️⃣ Set a Permanent Policy (Recommended for Developers)
Set-ExecutionPolicy RemoteSigned -Scope CurrentUser
-
RemoteSigned
allows local scripts but requires trusted signatures for downloaded scripts. - Applies only to your user account (no admin needed).
3️⃣ Use Command Prompt (CMD) Instead
PowerShell restrictions don’t apply in CMD. Simply run:
npm init -y
4️⃣ Verify the Current Policy
Get-ExecutionPolicy
- Should return
RemoteSigned
orBypass
if the fix worked.
Why This Happens?
- PowerShell restricts script execution by default (
Restricted
mode). -
npm.ps1
(Node.js’s PowerShell script) is blocked unless allowed.
Best Practice
- Use
RemoteSigned
for balance between security and usability. - If security is critical, revert later:
Set-ExecutionPolicy Restricted -Scope CurrentUser
✅ Now you can run npm init -y
without errors! 🎉
Thanks and Enjoy the Coding 🚀
Top comments (0)