【问题标题】:tsc : File C:\Program Files\nodejs\tsc.ps1 cannot be loaded because running scripts is disabled on this systemtsc :文件 C:\Program Files\nodejs\tsc.ps1 无法加载,因为在此系统上禁用了运行脚本
【发布时间】:2020-10-15 17:51:15
【问题描述】:

我正在尝试为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的屏幕截图:

有人知道我该如何解决这个错误吗?

【问题讨论】:

标签: javascript types


【解决方案1】:

PowerShell 有一些Execution Policies 告诉PS 如果用户尝试执行某些代码或脚本该怎么办。

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

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

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

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

Get-ExecutionPolicy

Get-ExecutionPolicy -List

你可以change execution policy点赞

Set-ExecutionPolicy -ExecutionPolicy Bypass -Scope CurrentUser

记住

在 Windows Vista 和更高版本的 Windows 中,要运行更改本地计算机执行策略的命令,LocalMachine 范围,请使用 以管理员身份运行选项启动 PowerShell

希望这会有所帮助。

【讨论】:

  • 非常感谢兄弟,这真的帮助了我并解决了我的问题......我现在明白了 :).. 非常感谢你
  • 耶稣回答疯狂的兄弟太好了谢谢哈哈哈
猜你喜欢
  • 2020-03-06
  • 2021-10-27
  • 2017-04-28
  • 2021-02-22
  • 2022-10-25
  • 2013-10-06
  • 2020-06-20
  • 2013-05-03
  • 2021-03-07
相关资源
最近更新 更多