【VSCode】vscode运行命令时提示“因为在此系统上禁止运行脚本”

前言

  • 安装好eslint后初始化,结果错误提示 " eslint : 无法加载文件 E:\Files\Development\Develop\nodejs\node_global\eslint.ps1,因为在此系统上禁止运行脚本。有关详细信息,请参阅 "


一、 问题:运行eslint --init报错

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

二、 原因:由于win系统策略原因禁止了某些脚本的运行,此时将其状态修改为允许即可

  • 以管理员的方式运行vscode,或者管理员运行powershell也可以,然后执行以下命令
  • 执行get-ExecutionPolicy,显示Restricted,表示状态是禁止的
  • 执行set-ExecutionPolicy RemoteSigned
  • 再执行get-ExecutionPolicy查看状态,显示RemoteSigned,表示允许状态
  • 此时运行你要执行的脚本命令便不会再报错
posted @ 2021-05-09 18:08  中国制造  阅读(675)  评论(0编辑  收藏  举报