DEV Community

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

Posted 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.
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode
  • 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
Enter fullscreen mode Exit fullscreen mode
  • 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
Enter fullscreen mode Exit fullscreen mode

4️⃣ Verify the Current Policy

Get-ExecutionPolicy
Enter fullscreen mode Exit fullscreen mode
  • 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
Enter fullscreen mode Exit fullscreen mode

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

Thanks and Enjoy the Coding 🚀

Top comments (0)