繁体   English   中英

tsc:文件 C:\Program Files\nodejs\tsc.ps1 无法加载,因为在此系统上禁用了运行脚本

[英]tsc : File C:\Program Files\nodejs\tsc.ps1 cannot be loaded because running scripts is disabled on this system

我正在尝试为file.ts运行命令tsc以将此代码编译为js ,但我发现以下错误:

tsc : File C:\Program Files\nodejs\tsc.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
+ tsc test.ts
+ ~~~
    + CategoryInfo          : SecurityError: (:) [], PSSecurityException
    + FullyQualifiedErrorId : UnauthorizedAccess

这是我的Editor的屏幕截图:

tsc 错误

任何人都知道我该如何解决这个错误?

PowerShell有一些执行策略,告诉PS如果用户尝试执行某些代码或脚本该怎么做。

如果执行策略是Undefined (大多数情况下),则应用的策略是Restricted

正如Restricted Policy中定义的那样,所有脚本文件的执行都被阻止。

阻止运行所有脚本文件,包括格式化和配置文件 ( .ps1xml )、模块脚本文件 ( .psm1 ) 和 PowerShell 配置文件 ( .ps1 )。

您可以按照此处的建议在PS中运行此命令来检查您当前的执行策略。

Get-ExecutionPolicy

或者

Get-ExecutionPolicy -List

您可以更改执行策略,例如

Set-ExecutionPolicy -ExecutionPolicy Bypass -Scope CurrentUser

记住

In Windows Vista and later versions of Windows, to run commands that change the execution policy for the local computer, LocalMachine scope, start PowerShell with the Run as administrator option.

希望这可以帮助。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM