
根据您提供的错误信息,我看到您在尝试运行pnpm命令时遇到了PowerShell执行策略的限制。这是一个Windows系统安全设置问题,不是代码本身的问题。以下是解决方案:
-
首先需要以管理员身份打开PowerShell
-
然后运行以下命令修改执行策略:
powershell
Set-ExecutionPolicy RemoteSigned -Scope CurrentUser
- 确认更改后,您可以再次尝试运行pnpm命令
-
以前执行Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Scope Process,每次编辑器关闭了,就要重新执行,重新下载pnpm
-
执行Set-ExecutionPolicy RemoteSigned -Scope CurrentUser,现在不用重复执行了
Set-ExecutionPolicy RemoteSigned -Scope CurrentUser
和 Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Scope Process
主要区别如下:
-
执行策略严格程度不同:
RemoteSigned
:允许运行本地脚本,但远程下载的脚本必须经过数字签名Unrestricted
:允许运行所有脚本,没有限制
-
作用范围不同:
-Scope CurrentUser
:只影响当前用户-Scope Process
:只影响当前PowerShell会话进程
-
持久性不同:
CurrentUser
设置会永久生效(写入注册表)Process
设置只在当前会话有效,退出后恢复原设置
-
安全性建议:
- 长期使用建议
RemoteSigned
- 临时调试可用
Unrestricted -Scope Process
- 长期使用建议
两者都是PowerShell的安全策略设置命令,但适用于不同场景。