简体   繁体   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

I am trying to run a command tsc for a file.ts as to compile this code to js but I fins the below error:我正在尝试为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

and here's a screen shot of my Editor :这是我的Editor的屏幕截图:

tsc 错误

any one knows how can I solve this error?任何人都知道我该如何解决这个错误?

PowerShell has some Execution Policies which tell PS what to do if user tries to execute some code or script. PowerShell有一些执行策略,告诉PS如果用户尝试执行某些代码或脚本该怎么做。

If the execution policy is Undefined , which is mostly the case, the applied policy is Restricted .如果执行策略是Undefined (大多数情况下),则应用的策略是Restricted

As defined in Restricted Policy , all script files execution is prevented.正如Restricted Policy中定义的那样,所有脚本文件的执行都被阻止。

Prevents running of all script files, including formatting and configuration files ( .ps1xml ), module script files ( .psm1 ), and PowerShell profiles ( .ps1 ).阻止运行所有脚本文件,包括格式化和配置文件 ( .ps1xml )、模块脚本文件 ( .psm1 ) 和 PowerShell 配置文件 ( .ps1 )。

You can check your current execution policy by running this command in PS as advised here .您可以按照此处的建议在PS中运行此命令来检查您当前的执行策略。

Get-ExecutionPolicy

OR或者

Get-ExecutionPolicy -List

You can change execution policy like您可以更改执行策略,例如

Set-ExecutionPolicy -ExecutionPolicy Bypass -Scope CurrentUser

Keep in mind记住

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. 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.

Hope this helps.希望这可以帮助。

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

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