这是 PowerShell 的执行策略拦截了 npm.ps1,不是 npm 坏了。最快处理有三种:
临时解决当前窗口:
powershell
Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass
然后再运行:
powershell
npm -v
npm install
这个只对当前 PowerShell 窗口有效,关掉就恢复。
推荐的长期解决:
用管理员或普通 PowerShell 都可以,执行:
powershell
Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy RemoteSigned
输入 Y 确认。之后重新打开 PowerShell,再试:
powershell
npm -v
不改策略的绕过方式:
直接用 npm.cmd:
powershell
npm.cmd install
或者换用 cmd.exe / Git Bash 运行 npm。
一般推荐第二种:CurrentUser + RemoteSigned,只影响当前用户,比改全局策略更稳。