解决vscode"无法加载文件 ,因为在此系统上禁止运行脚本"报错

问题

在使用 vscode 自带程序终端时,会报“无法加载文件 ,因为在此系统上禁止运行脚本”,这是因为 PowerShell 执行策略的问题。

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

解决方法:

  1. 以管理员身份运行 vscode
  2. 执行:get-ExecutionPolicy,会显示 Restricted,表示状态是禁止的;
  3. 执行:set-ExecutionPolicy RemoteSigned
  4. 再次执行:get-ExecutionPolicy,会显示 RemoteSigned,表示状态是允许的;

window.powershell解释说明

posted @ 2022-07-12 13:48  牛奔  阅读(458)  评论(0编辑  收藏  举报