簡體   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