Skip to content

npm.ps1 Cannot Be Loaded Because Running Scripts Is Disabled

PowerShell says npm.ps1 cannot be loaded because running scripts is disabled on this system. npm was found; PowerShell's execution policy refused to run its launcher. Why it started with npm 9.8.0, and the one-line fix that doesn't open your machine to every script.

npm-ps1 execution-policy powershell windows npm nodejs react-errors
BKG
Reading Progress

On This Page

For years this error belonged to people who installed Yarn or the Angular CLI globally. Then npm 9.8.0 came out in July 2023 with a new file in its bin folder, npm.ps1, and from that point every fresh Windows machine with a current Node.js started throwing "npm.ps1 cannot be loaded because running scripts is disabled on this system" at the very first npm create vite@latest. Nothing about Windows changed. npm did.

What PowerShell printed

This is Windows PowerShell 5.1, the blue one that ships with Windows and that VS Code opens by default:

PS C:\Users\dev\code> npm create vite@latest recipe-search
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 create vite@latest recipe-search
+ ~~~
    + CategoryInfo          : SecurityError: (:) [], PSSecurityException
    + FullyQualifiedErrorId : UnauthorizedAccess

PowerShell 7 prints the same sentence in its shorter error view, starting npm: File C:\Program Files\nodejs\npm.ps1 cannot be loaded... with no CategoryInfo block. Swap npm for npx, yarn, pnpm, ng or tsc and the path changes (global tools live under C:\Users\<you>\AppData\Roaming\npm\), but it's the same error with the same fix.

I didn't have a Windows machine for this run, so those two blocks are the message text as Windows prints it, not output I captured. Everything in the lab below I did run.

You were probably following a React tutorial. node -v worked. The very next command died. That order matters.

Found it, then refused to run it

The tempting read is "npm isn't installed properly", and I've watched people reinstall Node.js three times over this. Look at the message again. It names the file, C:\Program Files\nodejs\npm.ps1, with its full path. PowerShell searched your PATH, found npm, and then declined to run what it found.

So this isn't the 'npm' is not recognized problem, where the search comes up empty. The component that said no is PowerShell's script host, and the rule it applied is the execution policy: a per-machine and per-user setting that decides whether PowerShell will run .ps1 script files at all. Node.js didn't fail. npm never started.

Two minutes of checking, in the same PowerShell window:

Get-Command npm -All          # which npm files PowerShell can see, in the order it would use them
Get-ExecutionPolicy -List     # the policy at every scope
npm.cmd -v                    # the same npm, through the cmd launcher instead

If npm.cmd -v prints a version, your install is fine and the rest of this article is about one setting. If it also fails, you're in a different article.

Watching npm grow a .ps1 file

I wanted to know why a policy that has defaulted to Restricted on Windows desktops since PowerShell 1.0 only started biting npm users recently. So I pulled npm releases from the registry and listed their launchers. This ran on Linux (Ubuntu 22.04, Node.js 22.23.5, npm 10.9.9 driving the packs), which is fine, since the tarballs are the same on every OS.

mkdir npm-launchers && cd npm-launchers
for v in 8.19.4 9.7.2 9.8.0 10.9.9 12.2.3; do
  npm pack npm@$v --silent >/dev/null
  echo "$v: $(tar tzf npm-$v.tgz | grep -c 'package/bin/npm.ps1') npm.ps1"
done
8.19.4: 0 npm.ps1
9.7.2: 0 npm.ps1
9.8.0: 1 npm.ps1
10.9.9: 1 npm.ps1
12.2.3: 1 npm.ps1

I bisected the 9.x line to be sure: 9.7.2 has only npm.cmd, and 9.8.0 (published 2023-07-05) is the first with npm.ps1 and npx.ps1. The Node.js Windows installer copies these launchers into C:\Program Files\nodejs\, so every Node.js line still supported in 2026 drops an npm.ps1 right next to npm.cmd.

Then I wanted to see the policy side. I installed PowerShell 7.7.0 for Linux (arm64) into a scratch folder and asked it about execution policy:

mkdir ps77 && tar xzf powershell-7.7.0-linux-arm64.tar.gz -C ps77
./ps77/pwsh -NoProfile -Command 'Get-ExecutionPolicy -List; Set-ExecutionPolicy RemoteSigned -Scope CurrentUser'
        Scope ExecutionPolicy
        ----- ---------------
MachinePolicy    Unrestricted
   UserPolicy    Unrestricted
      Process    Unrestricted
  CurrentUser    Unrestricted
 LocalMachine    Unrestricted

Set-ExecutionPolicy: Operation is not supported on this platform.

That's the confirmation signal, in reverse. Off Windows, PowerShell reports Unrestricted everywhere and won't let you change it, which is why your teammate on a Mac running pwsh has never seen this. On a Windows 10 or 11 desktop, the same -List shows Undefined at every scope, and Undefined everywhere means the effective policy is Restricted: no .ps1 files run, interactive commands only.

Teardown: delete the npm-launchers and ps77 folders. Nothing was installed globally.

The short answer

PowerShell found npm.ps1 before npm.cmd, and your Windows execution policy is Restricted, so it refused to run any script file. Allow local scripts for your own user account and it goes away.

Why npm.ps1 runs instead of npm.cmd

When you type npm in PowerShell on Windows, it looks through each PATH folder for a match. In C:\Program Files\nodejs\ there are now two candidates, and PowerShell takes the .ps1 one. That preference is what flipped the switch in 2023: before npm 9.8.0 there was no npm.ps1, PowerShell picked npm.cmd, and a .cmd file is handed to cmd.exe, which the execution policy doesn't govern at all. The policy was Restricted the whole time. Nobody noticed, because npm never offered PowerShell a script.

One honest wrinkle from my lab: on Linux, pwsh preferred the plain npm executable over npm.ps1 in the same folder (Get-Command npm -All listed the Application first). Windows resolves the other way, and that's the whole reason this error exists.

What's in npm.ps1 is unexciting. I read the 12.2.3 copy: it finds node.exe next to itself, asks npm-prefix.js where npm lives, and calls node npm-cli.js with your arguments. The point of shipping it is argument handling. Running npm through cmd.exe mangles some PowerShell quoting, and a native .ps1 launcher passes your arguments through as you typed them.

The global tools got there earlier. npm uses cmd-shim to create Windows launchers for packages you install with -g, and I found .ps1 generation already in cmd-shim 3.0.3 from August 2019. That's why yarn.ps1 cannot be loaded and ng.ps1 cannot be loaded filled Stack Overflow long before npm itself joined them.

The policy scopes, from the highest priority down, are MachinePolicy and UserPolicy (both set by Group Policy), then Process, CurrentUser and LocalMachine. The first one that isn't Undefined wins. Microsoft's own about_Execution_Policies page says plainly that execution policy isn't a security system; it's a guard against running scripts by accident. Keep that in mind when someone tells you the fix is to turn it off.

Fixing npm.ps1 cannot be loaded without opening the whole machine

Here's the fix I use. It changes your user account only, needs no admin window, and survives reboots:

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
Get-ExecutionPolicy -List
npm -v

RemoteSigned lets scripts on your own disk run and still demands a signature for scripts that came from the internet (Windows tags downloaded files with a "Mark of the Web" stream). npm.ps1 was written to disk by the Node.js installer, so it runs. Windows PowerShell 5.1 asks you to confirm; answer Y.

What the circulating "fixes" cost:

What people paste What it does Use it?
-Scope CurrentUser RemoteSigned Local scripts run for you only Yes
-Scope Process Bypass Everything runs, this window only, gone when you close it Fine as a one-off
Set-ExecutionPolicy Unrestricted (admin) Every user, every script, downloaded ones run after a warning No
Bypass at LocalMachine No checks at all, machine-wide No
Deleting npm.ps1 PowerShell falls back to npm.cmd Comes back on the next Node.js or npm upgrade
Reinstalling Node.js Writes the same npm.ps1 again Never fixes this

If you set RemoteSigned and now get a different message, ...npm.ps1 is not digitally signed. You cannot run this script on the current system, your Node.js came from a zip you downloaded and extracted with Explorer, and every extracted file kept the internet tag. Get-ChildItem "C:\path\to\node" -Recurse | Unblock-File clears it, but I'd sooner run the .msi installer, which doesn't have the problem.

On a work laptop where the policy won't change

If Set-ExecutionPolicy replies that it succeeded but "the setting is overridden by a policy defined at a more specific scope", Get-ExecutionPolicy -List will show something set at MachinePolicy or UserPolicy. That's Group Policy. Your IT department owns it, and -Scope Process Bypass won't beat it either, since Process sits below both. Don't fight it. Type npm.cmd and npx.cmd instead of npm and npx, or switch the terminal you use to Command Prompt, which never consults the policy. Even a PowerShell profile with an alias won't help here, because under Restricted your profile script can't load either.

Set the machine up once

On my Windows setups I do two things on day one, before any React project exists. I set RemoteSigned at CurrentUser as above. And in VS Code I leave PowerShell as the default terminal but know where the switch is: terminal.integrated.defaultProfile.windows in settings.json, set to "Command Prompt" for machines where policy is locked.

Windows 11 has a toggle for the same thing under the developer settings page (Settings, then System, then For developers, then PowerShell). Turning it on allows local unsigned scripts. Check the result with Get-ExecutionPolicy -List rather than trusting the toggle, because the label has moved between builds.

None of this touches your npm scripts, by the way. npm run dev runs the dev script through cmd.exe on Windows by default, not PowerShell, so the policy only ever gated the npm command itself.

What to check after the next Node upgrade

  • A new Node.js install doesn't reset a CurrentUser policy, but a new Windows user profile, a fresh VM image or a reimaged laptop does. Put Get-ExecutionPolicy -List in your setup notes, next to the Node.js version your project needs.
  • If someone on the team deleted npm.ps1 as their fix, it's back after the upgrade. Expect the error again and point them here.
  • If a self-hosted Windows CI runner hits it, fix the policy for the account the runner service uses, with the same CurrentUser command run as that account. Don't sprinkle -ExecutionPolicy Bypass through the workflow files.
  • Global CLIs (yarn, pnpm, ng) each get their own .ps1 shim. One policy change covers all of them.

If you remember nothing else

  • The message names npm.ps1 with a full path, so npm was found. It's not a PATH problem and reinstalling won't help.
  • It started with npm 9.8.0, which began shipping npm.ps1 beside npm.cmd, and PowerShell on Windows runs the .ps1.
  • Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser is the fix. Skip Unrestricted.
  • Locked by Group Policy? Use npm.cmd, or a Command Prompt terminal.

Questions people search about this one

How do I fix "running scripts is disabled on this system" for npm?

Open PowerShell (no admin needed) and run Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser, confirm if it asks, then open a new terminal and run npm -v. That allows scripts stored on your machine for your account only. It works the same for npx, yarn, pnpm and ng.

Is it safe to set the execution policy to RemoteSigned?

For a developer's own account, yes, and it's the default on Windows Server. Scripts downloaded from the internet still need a signature, and the setting doesn't affect other users. Microsoft documents execution policy as an accident guard, not a security boundary, so RemoteSigned is the sensible middle ground; Unrestricted and Bypass give up more than you need.

Why does npm work in Command Prompt but not in PowerShell?

Command Prompt runs npm.cmd, and batch files aren't covered by PowerShell's execution policy. PowerShell finds npm.ps1 in the same folder and prefers it, and under the default Restricted policy it refuses. Since npm 9.8.0 both files ship with Node.js, which is why the difference appeared.

Can I fix it without admin rights?

Yes. The -Scope CurrentUser command doesn't need an elevated window. If Group Policy has set the policy, no command will override it; call npm.cmd directly or use a Command Prompt terminal, and ask IT if you need PowerShell scripts allowed. If npm isn't found at all, that's a different problem: see node is not recognized or npx is not recognized.

npm-ps1execution-policypowershellwindowsnpmnodejsreact-errors

BKG

Engineer and writer behind CODELZ. I read the stack trace, reproduce the bug, and explain why it happens, not just how to silence it. Plus honest reviews of the books and tools worth your time.

Comments