如何在VS Code终端中成功执行npm create vite@latest命令?
解决PowerShell中npm脚本未签名无法运行的问题
问题说明
在VS Code终端执行npm create vite@latest(注:你输入的命令写成了vital,正确应为vite)时,触发如下错误:
npm : File C:\Program Files\nodejs\npm.ps1 cannot be loaded. The file C:\Program Files\nodejs\npm.ps1 is not digitally signed. You cannot
run this script on the current system. For more information about running scripts and setting execution policy, see
about_Execution_Policies at https:/go.microsoft.com/fwlink/?LinkID=135170.
At line:1 char:1
- npm create vital@latest
+ CategoryInfo : SecurityError: (:) [], PSSecurityException + FullyQualifiedErrorId : UnauthorizedAccess
解决步骤
- 以管理员身份打开系统自带的PowerShell(不要用VS Code内的终端)
- 执行命令:
Set-ExecutionPolicy RemoteSigned - 弹出确认提示时,输入
Y并回车 - 关闭所有PowerShell窗口和VS Code,重新启动VS Code后,在终端执行正确的
npm create vite@latest命令
补充说明
RemoteSigned策略允许运行本地脚本,同时要求远程脚本必须经过数字签名,既满足npm的运行需求,也能维持基础安全防护。
内容的提问来源于stack exchange,提问作者SHNS MLCPR
相关产品推荐
相关产品推荐

