Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Next.js and React

PowerShell blocks npx because running scripts is disabled

Errornpx : File C:\Program Files\nodejs\npx.ps1 cannot be loaded because running scripts is disabled on this system.

Short answer

PowerShell's execution policy is Restricted on your account, so it will not run npx.ps1 or any other script. Run Get-ExecutionPolicy -List to see which scope sets it, then set RemoteSigned for the current user. If Group Policy sets it, you cannot override it from the shell.

  • Applies to Windows 11, PowerShell 5.1, PowerShell 7.6, Node.js 22
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    List the execution policy for every scope in precedence order. The row that is not Undefined and wins tells you what to change.

    Get-ExecutionPolicy -List
  2. 2Match what you see, then jump to its fix

    1. 1Every row of Get-ExecutionPolicy -List shows UndefinedNo policy is set, so Windows client falls back to RestrictedFix
    2. 2MachinePolicy or UserPolicy shows a value other than Undefined, or Set-ExecutionPolicy succeeds but the effective policy does not changeGroup Policy sets the policy and overrides your changeFix
    3. 3CurrentUser or Process shows Restricted or AllSignedA stricter policy is set for the current user or sessionFix

What does the error look like?

  • npx : File C:\Program Files\nodejs\npx.ps1 cannot be loaded because running scripts is disabled on this system.
  • + CategoryInfo : SecurityError: (:) [], PSSecurityException
  • + FullyQualifiedErrorId : UnauthorizedAccess

Cause 1 of 3

No policy is set, so Windows client falls back to Restricted

1Check

When all scopes are Undefined, the effective policy on a Windows client is Restricted, which permits single commands but no script files.

Get-ExecutionPolicy

2Fix

Set RemoteSigned for your own user only. Local scripts then run, and scripts downloaded from the internet must be signed.

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser

3Verify

The change is effective immediately. Run npx again in the same window.

Get-ExecutionPolicy -Scope CurrentUser
npx --version

Confirmed by learn.microsoft.com

Did this fix it?

Cause 2 of 3

Group Policy sets the policy and overrides your change

1Check

Group Policy overrides the policy set in every PowerShell scope, and a Set-ExecutionPolicy command can succeed while the effective policy stays the same.

Get-ExecutionPolicy -List

2Fix

Ask whoever manages the machine to change the Turn on Script Execution setting. For one session without touching any setting, you can start a new PowerShell with a different policy, but Group Policy still wins over it.

pwsh.exe -ExecutionPolicy RemoteSigned

3Verify

Run the command in the new session; the policy applies only to that session and its children.

npx --version

Confirmed by learn.microsoft.com

Did this fix it?

Cause 3 of 3

A stricter policy is set for the current user or session

1Check

Process and CurrentUser take precedence over LocalMachine, so a restrictive value there beats a permissive machine setting.

Get-ExecutionPolicy -List

2Fix

Change the scope that holds the strict value, or remove it by setting it to Undefined.

Set-ExecutionPolicy -ExecutionPolicy Undefined -Scope CurrentUser

3Verify

List the scopes again and run npx.

Get-ExecutionPolicy -List
npx --version

Confirmed by learn.microsoft.com

Did this fix it?

How do I stop it coming back?

  • Change the policy for CurrentUser only, never for the whole machine, unless you must.
  • Do not set Unrestricted or Bypass to silence the error; RemoteSigned is enough for local tooling.
  • On a work laptop, check with the administrator first, since Group Policy may manage this setting.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Web apps

tsconfig rejects allowImportingTsExtensions

An error that allowImportingTsExtensions needs noEmit or emitDeclarationOnly

allowImportingTsExtensions lets files import each other with .ts or .tsx extensions, and TypeScript only allows it together with noEmit or emitDeclarationOnly.

2 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.