DEV Community

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

Posted on

6 2 3 4

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 🚀

AWS Security LIVE! Stream

Streaming live from AWS re:Inforce

Tune into Security LIVE! at re:Inforce for expert takes on modern security challenges.

Learn More

Top comments (0)

DevCycle image

Fast, Flexible Releases with OpenFeature Built-in

Ship faster on the first feature management platform with OpenFeature built-in to all of our open source SDKs.

Start shipping

👋 Kindness is contagious

Dive into this thoughtful piece, beloved in the supportive DEV Community. Coders of every background are invited to share and elevate our collective know-how.

A sincere "thank you" can brighten someone's day—leave your appreciation below!

On DEV, sharing knowledge smooths our journey and tightens our community bonds. Enjoyed this? A quick thank you to the author is hugely appreciated.

Okay