PowerShell blocks npx because running scripts is disabled
npx : 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.
Fix it fast
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 -List2Match what you see, then jump to its fix
- 1
Every row of Get-ExecutionPolicy -List shows UndefinedNo policy is set, so Windows client falls back to RestrictedFix - 2
MachinePolicy 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
CurrentUser or Process shows Restricted or AllSignedA stricter policy is set for the current user or sessionFix
- 1
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-ExecutionPolicy2Fix
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 CurrentUser3Verify
The change is effective immediately. Run npx again in the same window.
Get-ExecutionPolicy -Scope CurrentUser
npx --versionConfirmed by learn.microsoft.com
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 -List2Fix
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 RemoteSigned3Verify
Run the command in the new session; the policy applies only to that session and its children.
npx --versionConfirmed by learn.microsoft.com
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 -List2Fix
Change the scope that holds the strict value, or remove it by setting it to Undefined.
Set-ExecutionPolicy -ExecutionPolicy Undefined -Scope CurrentUser3Verify
List the scopes again and run npx.
Get-ExecutionPolicy -List
npx --versionConfirmed by learn.microsoft.com
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 fixWeb apps
Apollo Server rejects a request as a potential CSRF
HTTP 400 Bad Request from the GraphQL endpoint
Apollo Server's CSRF prevention is on by default.
3 causes, each with a fixWeb apps
React shows Attempted import error when importing a component or function
Attempted import error:
The build found the file but not the name you asked for.
2 causes, each with a fixWeb apps
AxiosError Network Error with code ERR_NETWORK in a React app
Network Error
ERR_NETWORK means the request produced no readable response.
4 causes, each with a fixWeb apps
Axios get works with a URL string but ignores the object passed as the second argument
The server log shows a GET with no query string
axios.get takes a URL and an optional config object.
3 causes, each with a fixWeb apps
Can't resolve '../axios' in a React project
Module not found: Error: Can't resolve '../axios'
A path that starts with ./ or ../ is a file path, not the axios package.
3 causes, each with a fix