Execution policy errors in Windows PowerShell for npm.ps1 and npx.ps1 scripts.
The issue involves execution policy errors when running npm.ps1 and npx.ps1 scripts in Windows PowerShell. The problem is reproducible and requires a fix to ensure these scripts run without triggering execution policy alarms. The scope is somewhat clear but involves Windows-specific PowerShell behavior.
v24.14.1
Microsoft Windows NT 10.0.26200.0 x64
bundled npm.ps1 and npx.ps1 scripts
I usually install node on my Windows machines by downloading the ZIP bundle (LTS) and unpacking it into 'C:\Program Files' and setting the path (NOTE: I have to give admin consensus to add a folder to that directory). The latest version I did not have problems with this approach was Node 20.
In Node 24, I notice that Npm and Npx are now delivered also with .ps1 scripts, contrary to Node 20 where only .cmd scripts were bundled.
Invoking these scripts in Windows Powershell doesn't seem to work and ExecutionPolicy errors are returned.
WORKAROUND: in Powershell, don't launch npmand npx, but use explicitly npm.cmd and npx.cmd. This will force to use the old cmd.exe scripts. My understanding is that powershell piping will not work with these but they will launch correctly as individual commands.
100% frequency, reproduced on 2 machines with Windows 11 and latest updates. Both with node-24 zip distribution.
Invoking npmand npx from the Windows's bundled Powershell (version 5.1) cmd line should work.
Invoking npmand npx from the Windows Powershell (version 5.1) cmd line seem to trigger the Windows NT "Execution Policy" alarm.
(Unfortunately since my Windows install is in Italian, also Powershell outputs error messages in italian -- apologies).
PS C:\Program Files\node-v24.14.1-win-x64> npm --version
npm : Impossibile caricare il file C:\Program Files\node-v24.14.1-win-x64\npm.ps1. Il file C:\Program
Files\node-v24.14.1-win-x64\npm.ps1 non è firmato digitalmente. Lo script non può essere eseguito nel sistema
corrente. Per ulteriori informazioni sull'esecuzione di script e l'impostazione di criteri d
Claim this issue to let others know you're working on it. You'll earn 20 points when you complete it!