DEV Community

Cover image for Troubleshooting `npm` init Error in PowerShell
Sajjad Rahman
Sajjad Rahman

Posted on Edited on

Troubleshooting `npm` init Error in PowerShell

Problem:

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



![unthorized](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ghn3j856lehny6xeuwax.png) 



npm : File C:\Program Files\nodejs\npm.ps1 cannot be loaded because running scripts is disabled on this system.
✨ Latest Report: sajjadrahman/troubleshooting npm init error in powershell d - Latest Analysis ✨ Latest Report: sajjadrahman/troubleshooting npm init error in powershell d - Latest Analysis

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
✨ Latest Report: sajjadrahman/troubleshooting npm init error in powershell d - Latest Analysis ✨ Latest Report: sajjadrahman/troubleshooting npm init error in powershell d - Latest Analysis
  • 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
✨ Latest Report: sajjadrahman/troubleshooting npm init error in powershell d - Latest Analysis ✨ Latest Report: sajjadrahman/troubleshooting npm init error in powershell d - Latest Analysis
  • 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
✨ Latest Report: sajjadrahman/troubleshooting npm init error in powershell d - Latest Analysis ✨ Latest Report: sajjadrahman/troubleshooting npm init error in powershell d - Latest Analysis

4️⃣ Verify the Current Policy

Get-ExecutionPolicy
✨ Latest Report: sajjadrahman/troubleshooting npm init error in powershell d - Latest Analysis ✨ Latest Report: sajjadrahman/troubleshooting npm init error in powershell d - Latest Analysis
  • Should return RemoteSigned or Bypass 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
✨ Latest Report: sajjadrahman/troubleshooting npm init error in powershell d - Latest Analysis ✨ Latest Report: sajjadrahman/troubleshooting npm init error in powershell d - Latest Analysis

✅ Now you can run npm init -y without errors! 🎉

Thanks and Enjoy the Coding 🚀

Top comments (0)