pnpm:无法加载文件,因为在此系统上禁止运行脚本。有关详细信息,请参阅xxx中的about_Execution_Policies

问题

1
2
3
4
5
6
7
pnpm : 无法加载文件 D:\develop\nvm\node\pnpm.ps1,因为在此系统上禁止运行脚本。有关详细信息,请参阅 https:/go.microsoft.com/fwlink/?LinkID=135170 中的 about_Execution_Policies。
所在位置 行:1 字符: 1
+ pnpm install
+ ~~~~
+ CategoryInfo : SecurityError: (:) [],PSSecurityException
+ FullyQualifiedErrorId : UnauthorizedAccess

原因

Power Shell的执行策略限制了脚本的执行

查看当前策略

1
Get-ExecutionPolicy

策略:

  • Restricted:默认策略,禁止运行任何脚本,除非明确允许。
  • AllSigned:只允许运行经由数字签名并由受信任的发布者签名的脚本。
  • RemoteSigned:允许运行未经签名的脚本,但是必须由受信任的发布者在本地计算机上签名。
  • Unrestricted:允许运行所有脚本。

解决

1
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope Process -Force

本文地址: https://github.com/maxzhao-it/blog/post/21566xciohsdf/