Yarn 运行时提示 yarn.ps1 cannot be loaded 错误

完整的错误信息如下:

PS C:\WorkDir\USVisaTrack\Source-Code\UI\Usvisatrack-Ui> yarn -v
yarn : File C:\Users\annch\AppData\Roaming\npm\yarn.ps1 cannot be loaded because running scripts is disabled on this system. For more information, see about_Execution_Policies at https:/go.microsoft.com/fwlink/?LinkID=135170.
At line:1 char:1
+ yarn -v
+ ~~~~
    + CategoryInfo          : SecurityError: (:) [], PSSecurityException
    + FullyQualifiedErrorId : UnauthorizedAccess

完整的错误的错误界面如下:

问题和原因

可能的原因是你的系统没有权限执行 yarn 这个命令。

尝试以管理员权限运行:

Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Unrestricted

在执行完上面的命令后,再查看 yarn 的版本。

如果在 IDEA 中运行 yarn 这个命令的话,你也可以看到相同的结果。

1 Like