Search code examples
javascripttypes

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 error

any one knows how can I solve this error?


Solution

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