yarn : 无法加载文件 D:\ProgramFiles\nodejs\yarn.ps1,因为在此系统上禁止运行脚本

错误信息

yarn : 无法加载文件 D:\ProgramFiles\nodejs\yarn.ps1,因为在此系统上禁止运行脚本。有关详细信息,请参阅 https:/go.microsoft.com/fwlink/?LinkID=135170 
中的 about_Execution_Policies。
所在位置 行:1 字符: 1
+ yarn run serve
+ ~~~~
    + CategoryInfo          : SecurityError: (:) [],PSSecurityException
    + FullyQualifiedErrorId : UnauthorizedAccess
终端进程“C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -Command yarn run serve”已终止,退出代码: 1。
 

主要原因是powershell的执行策略阻止了此次操作


解决

在powershell命令行

windows下运行*.ps1脚本(powershell的脚本)的时候,需要设置执行权限

执行命令: set-ExecutionPolicy RemoteSigned #远程签名
#Set-ExecutionPolicy Restricted #不允许执行(默认选项)
#Set-ExecutionPolicy Unrestricted #无限制
#参数 -Scope CurrentUser 仅当前用户有效

-----------------------------------------------------------------
Get-ExecutionPolicy
Get-ExecutionPolicy -Scope CurrentUser

猜你喜欢

转载自blog.csdn.net/JackieDYH/article/details/125302757