简体   繁体   中英

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:

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 :

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.

If the execution policy is Undefined , which is mostly the case, the applied policy is Restricted .

As defined in Restricted Policy , all script files execution is prevented.

Prevents running of all script files, including formatting and configuration files ( .ps1xml ), module script files ( .psm1 ), and PowerShell profiles ( .ps1 ).

You can check your current execution policy by running this command in PS as advised here .

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.

Hope this helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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