Set the PowerShell execution policy to RemoteSigned for your user account, then run npm init again.
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
Get-ExecutionPolicy
npm init
Accept the confirmation prompt by entering Y. The change takes effect immediately, does not require administrator privileges at CurrentUser scope, and persists for your account. RemoteSigned permits local scripts such as npm.ps1 while requiring downloaded scripts to be signed or explicitly unblocked.^1^
Avoid setting Bypass or Unrestricted system-wide; those policies remove protections that are unnecessary for this npm error.
If the error continues
Display every applicable policy:
Get-ExecutionPolicy -List
PowerShell applies policies in this order: MachinePolicy, UserPolicy, Process, CurrentUser, and LocalMachine, with Group Policy overriding settings configured through Set-ExecutionPolicy.^2^
- If
MachinePolicy or UserPolicy is Restricted or AllSigned, the device is probably managed through Group Policy. Contact the administrator rather than attempting to bypass it.
- An administrator can configure Turn on Script Execution under:
Computer Configuration or User Configuration → Administrative Templates → Windows Components → Windows PowerShell
- The appropriate managed setting is normally Allow local scripts and remote signed scripts, equivalent to
RemoteSigned.^3^
If policy permits scripts but a later message says a particular script is not digitally signed, only unblock that file when its source is trusted:
Unblock-File -Path "C:\path\to\trusted-script.ps1"
References
- Chapter 1 - Getting started with PowerShell
- about_Execution_Policies
- about_Group_Policy_Settings