Fixing npm.ps1 Cannot Be Loaded Because Running Scripts is Disabled on Windows

Let's Solve the Execution Policy Error and Get Back to Coding

Unblocking NPM on Windows
BJ
Bob James
2 min read
1 votes
0 comments

Learn how to fix the 'npm.ps1 cannot be loaded' error in PowerShell by safely updating your execution policy on Windows.

You're all set, installed VS Code and Node Package Manager on a fresh Windows setup, ready to code.

You type npm install and… boom, this error blindsides you:

Shell
npm : File C:\Program Files\nodejs\npm.ps1 
cannot be loaded because running scripts is disabled on this system.
For more information, see about_Execution_Policies at 
https:/go.microsoft.com/fwlink/?LinkID=135170.
At line:1 char:1
+ npm install
+ ~~~
    + CategoryInfo          : SecurityError: (:) [], PSSecurityException
    + FullyQualifiedErrorId : UnauthorizedAccess

No need to panic at all, in fact this is a super common PowerShell security enforcement policy setting that prevents script execution by default.

It's called a Windows Powershell Execution Policy and here's how to fix it to work with npm:

To set the execution policy to RemoteSigned, and with CurrentUser Scope, open up Windows Powershell as Administrator, and enter the following command and press Enter:

Shell
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser

You will be prompted as follows:

Shell
Execution Policy Change
The execution policy helps protect you from scripts that you do not trust.
Changing the execution policy might expose you to the security risks
described in the about_Execution_Policies help topic at
https:/go.microsoft.com/fwlink/?LinkID=135170.

Do you want to change the execution policy?
[Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "N"): Y

To continue, and save the change, which is saved in the configuration file and remains effective until you change it again, press Y and Enter to confirm.

This allows trusted local scripts to run, and remote scripts only if they're signed...

a developer-friendly setting indeed!

The change is effective immediately and you don't even need to restart PowerShell.

Want to dig into Windows Powershell Execution Policies?

👉 Windows Powershell Execution Policies by Microsoft Learn

Login to vote on this article

Share:

Discussion

Login to add a comment

No comments yet 🤯 but its such an awesome article.
Be the first to comment and start a discussion 🤗