Share via

how can the error message below be fixed?

Steven Andelman 0 Reputation points
2026-04-24T11:06:59.6533333+00:00

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 init -y
  • 
        + CategoryInfo          : SecurityError: (:) [
    
       ], PSSecurityException
    
        + FullyQualifiedErrorId : UnauthorizedAccess
    
Microsoft Copilot | Other
0 comments No comments

1 answer

Sort by: Most helpful
  1. AI answer

    2026-04-24T11:07:12.47+00:00

    The error occurs because the PowerShell execution policy is blocking scripts like npm.ps1. To fix it, either change the execution policy to allow scripts, or unblock the specific script.

    Option 1: Change execution policy (recommended for development machines)

    1. Open PowerShell as Administrator.
    2. Check the current policy:
         Get-ExecutionPolicy
      
    3. Set a less restrictive policy, for example RemoteSigned for the current user (no admin needed for this scope):
         Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
      
      If changing for the whole machine (requires admin):
         Set-ExecutionPolicy -ExecutionPolicy RemoteSigned
      
    4. Close and reopen PowerShell, then run:
         npm init -y
      

    RemoteSigned allows local scripts to run and requires downloaded scripts to be signed by a trusted publisher.

    Option 2: Allow scripts only for this session/process

    If changing the global or user policy is not desired:

    1. Start PowerShell with a relaxed policy just for this process:
         pwsh.exe -ExecutionPolicy RemoteSigned
      
      or inside an existing session:
         Set-ExecutionPolicy -Scope Process -ExecutionPolicy RemoteSigned
      
    2. Run npm init -y in that session. The change applies only to that PowerShell process.

    Option 3: Unblock the specific script file

    If the script is blocked because it is marked as downloaded from the internet and the policy is RemoteSigned:

    1. In PowerShell, run:
         Get-Item "C:\Program Files\nodejs\npm.ps1" -Stream "Zone.Identifier" -ErrorAction SilentlyContinue
      
      If a Zone.Identifier stream exists, unblock it:
         Unblock-File -Path "C:\Program Files\nodejs\npm.ps1"
      
    2. Run npm init -y again.

    Before changing execution policies or unblocking files, review the security implications and ensure the scripts being run are trusted.


    References:

    AI-generated content may be incorrect. Read our transparency notes for more information.

    Was this answer helpful?

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.