VSCode【因为在此系统上禁止运行脚本】

错误

vscode终端运行vue -V查看版本失败

PS C:\Users\11388> vue -V
vue : 无法加载文件 E:\NodeJs\node_global\vue.ps1,因为在此系统上禁止运行脚本。有关详细信息,请参阅 https:/go.microsoft.com/fwlink/?LinkID=135170 中的 about_Execution_Policies。
所在位置 行:1 字符: 1
+ vue -V
+ ~~~
    + CategoryInfo          : SecurityError: (:) [],PSSecurityException
    + FullyQualifiedErrorId : UnauthorizedAccess
    +  

在系统终端中运行vue -V查看版本却成功
在这里插入图片描述

原因

计算机上启动 Windows PowerShell 时,执行策略为 Restricted(默认设置)。
Restricted 执行策略不允许任何脚本运行。
RemoteSigned 执行策略可防止 Windows PowerShell 运行没有数字签名的脚本。

有关 Windows PowerShell 执行策略的详细信息,请参阅 :
https://docs.microsoft.com/zh-cn/powershell/module/microsoft.powershell.core/about/about_execution_policies?view=powershell-7]

解决方案

  1. 右键选择vscode,点击属性
    在这里插入图片描述
  2. 选择兼容性,勾选以管理员身份运行此程序
    在这里插入图片描述
  3. 重新打开vscode,打开终端执行下面2个命令
get-ExecutionPolicy // 查看执行策略
set-ExecutionPolicy RemoteSigned // 设置执行策略

在这里插入图片描述

posted @ 2022-09-14 14:09  yangstar  阅读(256)  评论(0编辑  收藏  举报