39
votes

On PowerShell, I got the error message when executing tsc. This never happened before.

I am not sure should I mingle with the PowerShell security settings to rectify this such as based on this one: PowerShell says "execution of scripts is disabled on this system."

Update

This is a new intended feature by npm to use ps1 scripts. A question has been raised in their repo: https://github.com/npm/cli/issues/470

9
You don't have much choice. The script execution policy needs to be set to allow running of .ps1 scripts on a Windows system. You can avoid by running within Powershell ISE or similar but otherwise the system policy will dictate.Scepticalist
I realised the older version of npm will not include the ps1 file, not sure why they started doing now.Cerlancism
There is nothing wrong with setting the PowerShell script execution policy to at least "RemoteSigned".Ansgar Wiechers
@Ansgar Wiechers alright thenCerlancism

9 Answers

100
votes

You can run this in PowerShell command. Be sure to run it as administrator:

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned
43
votes

Use tsc.cmd instead of tsc. For example:

tsc.cmd -v
tsc.cmd --init
11
votes

Open Commandform : windows + R

Type : Powershell

Then type : set-executionpolicy remotesigned

And select opetion : A

10
votes

this problem happend with me the solution is tsc.cmd [filename.ts]

it will work

4
votes

If you are using Visual Studio Code you can use tsc.cmd instead of tsc. It worked fine for me.

1
votes

Use tsc.cmd instead of tsc

example:

Before : tsc script.ts | node script.js

After : tsc.cmd script.ts | node script.js

1
votes

You can also go to File > Settings > Extensions > JSON > Schema and add this to that JSON:

"terminal.integrated.shellArgs.windows": ["-ExecutionPolicy", "Bypass"]

Restart and it should work.

0
votes

If your using Powershell as default shell then you will get this error on Running: as shown

To fix this you can have following option. you can choose any of these to short out your issue:

  1. you have to enable execution policy by following command in PS(Powershell):

    Set-ExecutionPolicy -ExecutionPolicy RemoteSigned

once its enable you able to run tsc command directly.

  • Since Powershell is default terminal shell you use following command to run all typescript related commands like :

    tsc.cmd -v

  • You can change you default shell from Powershell to cmd by following method in Visual studio code. then using cmd shell you can use typescript normally like tsc -v instead of using tsc.cmd -v

steps to enable cmd.exe as default shell for VS Code:

  • Press ctrl+shift+p

  • Press 'terminal: select default profile' as shown

  • Select cmd.exe as default terminal shell. as shown

  • Now in terminal window you will see cmd.exe as shown

0
votes

"File Cannot Be Loaded Because Running Scripts Is Disabled on This System In Windows Powershell FIX." This is observed in latest update in permissions by windows all we need to do is search for Powershell in windows start and run as administartor and runn the followiing commands which is given below.

If you are running into an error saying that your script "cannot be loaded because running scripts is disabled on this system" while trying to run a script in Powershell, on Windows 10, you have to change the execution policies first.

Commands to be entered in power shell:

1)Get-ExecutionPolicy -List

2)Set-ExecutionPolicy Unrestricted

3)Set-ExecutionPolicy Unrestricted -Force

Note:- u will be prompted to give Y/N after giving the 2nd command,so give as 'Y' and click on enter button

If PowerShell throws up an error message – File cannot be loaded because running scripts is disabled on this system, then you need to enable script running on your Windows 10 computer. The cause of this error comes to the fact that your user account does not have enough permissions to execute that script. This does not mean that you need to have an Administrator level permissions, it also means that you also need to be unrestricted to run these type of PowerShell scripts or cmdlets