This PowerShell error occurs when Windows' execution policy is set to Restricted, preventing npm scripts from running. The fix involves changing the execution policy to RemoteSigned using Set-ExecutionPolicy.
This error occurs when Windows PowerShell's execution policy is set to "Restricted" (the default on Windows 10 and Windows 11), preventing any scripts from running. When npm tries to execute its PowerShell wrapper script (npm.ps1), PowerShell blocks it as a security measure. The error specifically indicates that the npm.ps1 file cannot be loaded because the system policy prohibits script execution. This became common after npm version 6.9.0, when npm began using PowerShell wrapper scripts to enhance the Windows experience. The execution policy is a security boundary designed to prevent accidental execution of malicious scripts, but it also blocks legitimate development tools like npm from functioning properly in PowerShell.
Launch PowerShell with elevated privileges, which is required to change the execution policy:
1. Click the Windows Start menu
2. Type "PowerShell"
3. Right-click "Windows PowerShell" (not Windows PowerShell ISE)
4. Select "Run as administrator"
5. Confirm the User Account Control prompt if it appears
Verify you're running as administrator by checking for [Admin] in the window title.
Run this command to see what policy is currently preventing script execution:
Get-ExecutionPolicy -ListThis will display the execution policy at each scope (MachinePolicy, UserPolicy, Process, CurrentUser, LocalMachine). The "CurrentUser" or "LocalMachine" scope showing "Restricted" is what prevents npm from running.
Run this command to enable locally created scripts while maintaining security for downloaded scripts:
Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy RemoteSignedYou'll see a prompt asking to confirm the change. Type Y and press Enter.
The RemoteSigned policy allows scripts written locally (like npm) to run without signatures, while requiring scripts downloaded from the internet to be signed by a trusted publisher.
Confirm the policy was updated and test that npm now works:
Get-ExecutionPolicy
# Should return: RemoteSigned
npm --version
# Should display npm version without the execution policy error
npm install
# Or whatever npm command was failing beforeIf you prefer not to change PowerShell's execution policy, you can simply use the traditional Command Prompt (cmd.exe) instead, which does not have execution policy restrictions:
# Open Command Prompt and run npm commands
npm install
npm startCommand Prompt does not use PowerShell scripts and will work without any policy changes.
Execution Policy Levels Explained:
- Restricted (Default): No scripts run, only individual commands execute.
- AllSigned: Only scripts signed by trusted publishers run.
- RemoteSigned (Recommended): Local scripts run freely; scripts from the internet must be signed.
- Unrestricted: All scripts run regardless of origin. Not recommended.
- Bypass: No policy restrictions. Generally unsafe.
Scope Levels:
- CurrentUser: Affects only the current user's PowerShell sessions (safest)
- LocalMachine: Affects all users on the computer (requires administrator)
- Process: Affects only the current PowerShell window (reverts when closed)
Temporary Session-Only Fix: If you want to enable npm just for the current PowerShell session without permanent changes:
Set-ExecutionPolicy -Scope Process -ExecutionPolicy RemoteSignedCorporate/Domain-Enforced Policies: If you're on a corporate network and cannot change the execution policy (greyed out in settings), your IT department has enforced a Group Policy. Contact IT support or use Command Prompt instead.
npm notice access token expired or revoked. Please try logging in again.
Token has expired - npm authentication failure
npm ERR! code EAI_AGAIN
How to fix "EAI_AGAIN" in npm
npm error code E403 npm error 403 Forbidden - PUT https://registry.npmjs.org/<package>
How to fix 'E403 Forbidden' error in npm
npm ERR! code EUSAGE npm ERR! Usage error
How to fix "npm ERR! code EUSAGE" in Node.js projects
npm ERR! code E401 npm ERR! 401 Unauthorized
How to fix "E401 Unauthorized" in npm