105

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

4
  • 1
    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. Commented Nov 11, 2019 at 8:24
  • I realised the older version of npm will not include the ps1 file, not sure why they started doing now. Commented Nov 11, 2019 at 9:24
  • 2
    There is nothing wrong with setting the PowerShell script execution policy to at least "RemoteSigned". Commented Nov 11, 2019 at 9:51
  • @Ansgar Wiechers alright then Commented Nov 11, 2019 at 10:04

25 Answers 25

217

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

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned
Sign up to request clarification or add additional context in comments.

11 Comments

can you give some more details to what this does? and how safe it is?
It is super important to run the PowerShell as Administrator
Please provide details on what it is and what it does. I see so many upvotes on an answer with no explanation. Please don't make SO a site where people come for hacks instead of learning.
Very good solution, solved my problem with typescript
Can add -Scope CurrentUser to avoid having to log in as admin
|
148

Use tsc.cmd instead of tsc. For example:

tsc.cmd -v
tsc.cmd --init

1 Comment

Just for clarification: tsc is a bash script - tsc.cmd is a Windows version of the script.
35

Open Command_form: windows + R

Type: Powershell

Then type:

set-executionpolicy remotesigned

And select option: A

1 Comment

Please try to run the windows power shell in admin mode And try this command, and this solution solved the same problem for me.
22

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

it will work

4 Comments

This seems a bit unclear - question was regarding a powershell script. You're proposing to use tsc.cmd to run a typescript file - maybe expand a bit, and tell where to get the ts file and how i relates to tsc.ps1
github.com/npm/cli/issues/470#issuecomment-586845035 npm in Windows will still install a cmd version
I don't know why it's downvoted, but I found this useful, rather than changing execution policy in PowerShell.
This should be the accepted answer. The fix is on the npm developer side. They should name their ps script differently from the compiled executable.
13

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

1 Comment

this does it for me
10

Solved

The error "tsc.ps1 cannot be loaded because running scripts is disabled on this system" occurs when the execution policy does not allow running the specific script on Windows.

To solve this issue you can use any of these three methods:


  1. Use the Set-ExecutionPolicy -ExecutionPolicy RemoteSigned command to solve the error.

Open your PowerShell as an administrator and set its execution policy with the Set-ExecutionPolicy command.

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned

If you aren't able to run the command as an administrator, try running it with the CurrentUser parameter.

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser

The Get-ExecutionPolicy command should display the execution policy for the current session (RemoteSigned). Use it to confirm if you have changed it.

Get-ExecutionPolicy
  1. Add .cmd to the command

By adding .cmd to the command it tells PowerShell to use the cmd version instead.

tsc.cmd -v

tsc.cmd --init

tsc.cmd myFile.ts
  1. You can also try prefixing the tsc command with npx

The npx prefix is an npm package runner that can run packages from the npm registry without installing them.

npx tsc -v

npx tsc --init

npx tsc myFile.ts

Read more from https://bobbyhadz.com/blog/typescript-tsc-cannot-be-loaded-because-running-scripts-disabled

Comments

9

Use tsc.cmd instead of tsc

example:

Before : tsc script.ts && node script.js

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

1 Comment

5

In VS Code, use tsc.cmd instead of tsc. For example:

tsc.cmd -v

Comments

4

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

To fix this you have the following options. you can choose any of these to sort out your issue:

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

    Set-ExecutionPolicy -ExecutionPolicy RemoteSigned

once it's enabled you can run tsc command directly.

  • Since Powershell is the default shell terminal, 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

1 Comment

Would like to insert your images directly in the text, or do prefer to leave them as links ?
2
  1. Open your PowerShell as an administrator and set its execution policy with the "get-ExecutionPolicy" command. it will show you restricted.

  2. type "Set-ExecutionPolicy Unrestricted"

  3. ask you yes for all type [A]

Other Option

  1. Type "Set-ExecutionPolicy -ExecutionPolicy RemoteSigned"

  2. check tsc --int

  3. See below steps

enter image description here

1 Comment

Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
1

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.

Comments

1

I had a problem like this. I have solved my problem with doing this:

  1. Try this: open terminal/cmd and type: npm install typescript --save-dev,
  2. compile with: npx tsc or you can do this: npx tsc --watch. More about that: https://www.typescriptlang.org/download.

Comments

1

Okay, I had the same problem however, I was able to solve the issue by looking into my anti-virus software and turned off my auto-container and using the command: tsc.cmd <file.ts>

solved my issue!

Comments

1

Use tsc.cmd instead of tsc. For example:

tsc.cmd -v
tsc.cmd --init

1 Comment

Why would this start happening to me? All I did was install typescript globally. npm install -g typescript.
1

Solved: Open PowerShell in admin mode.

Type Below command:

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned

Comments

0

"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

1 Comment

No, this is a workaround, and a dangerous one at that. This should be deleted.
0

In visual studio code-> terminal ->open new terminal Then in right corner of terminal there is an arrow ↓ besides + sign -> select "cmd" Then you can run tsc filename.ts command without using tsc. cmd filename.ts Then use node filename Here is your output... taaaa-daaaaa

Comments

0

in VS code it will be solve by adding this code to the setting.json.

"terminal.integrated.profiles.windows": {
  "PowerShell": {
    "source": "PowerShell",
    "icon": "terminal-powershell",
    "args": ["-ExecutionPolicy", "Bypass"]
  }
},
"terminal.integrated.defaultProfile.windows": "PowerShell",

refrence

Comments

0

if you do just this

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned

you might be greeted with the error

Set-ExecutionPolicy : Access to the registry key 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell' is denied. To change the execution policy for
the default (LocalMachine) scope, start Windows PowerShell with the "Run as administrator" option. To change the execution policy for the current user, run "Set-ExecutionPolicy
-Scope CurrentUser". At line:1 char:1

  • Set-ExecutionPolicy -ExecutionPolicy RemoteSigned
  •   + FullyQualifiedErrorId : System.UnauthorizedAccessException,Microsoft.PowerShell.Commands.SetExecutionPolicyCommand
    
    

So, what you have to do is run windows powershell as administrator then type this:

Set-ExecutionPolicy -Scope CurrentUser

Then set,

ExecutionPolicy: remotesigned

Then say yes to all by typing A and everything will be okay. goodlu

Comments

0

I strongly recommend to install the new open-source powershell if you're on windows https://github.com/PowerShell/PowerShell/releases

This fixed all our woes, including running scripts being disabled. We also had issues with git bash regarding the way paths are handled differently (ex: backslash, forward slash).

It's the simplest and most foolproof solution in my opinion, I hope it helps.

Comments

0

Below command works for me. Run in Shell Terminal as Administrator:

For more information check the detailed blog by ms

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned

Or

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser

enter image description here

Comments

0

This is how solved this issues.

1-> Open windows PowerShell as administration
2-> enter command: Get-ExecutionPolicy
3-> enter command : Set-ExecutionPolicy RemoteSigned
4-> enter command: Y
5-> enter command to check npm: npm --version

Issue: npm : File C:\Program Files\nodejs\npm.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

  • npm install -g @angular/cli@17
  •   + CategoryInfo          : SecurityError: (:) [], PSSecurityException
      + FullyQualifiedErrorId : UnauthorizedAccess
    

Comments

0

The error occurs because PowerShell's execution policy is set to restrict running scripts, which prevents tsc.ps1 from executing.

Fix: Enable Script Execution You need to change the execution policy in PowerShell. Follow these steps:

  1. Open PowerShell as Administrator Press Win + X → Click PowerShell (Admin) If using Windows Terminal, open it and choose PowerShell as Admin.
  2. Allow Scripts to Run Run the following command:

powershell

Set-ExecutionPolicy Unrestricted -Scope CurrentUser

If prompted, type Y and press Enter.

  1. Verify Execution Policy To check if the policy changed, run:

powershell

Get-ExecutionPolicy -Scope CurrentUser

It should return Unrestricted.

  1. Run TypeScript Compiler Now, try running TypeScript again:

powershell/visualstudio code terminal/bash

tsc app.ts

Alternative Fix (Without Changing Execution Policy) If you don’t want to change execution policies, you can bypass PowerShell and use Node.js directly:

bash

npx tsc app.ts

or explicitly run tsc.cmd:

bash C:\Users\username\AppData\Roaming\npm\tsc.cmd app.ts

Comments

-1

Another solution for the above problem is if you are using VScode or Visual Studio Code.

  1. Open the vscode termial by using Ctrl + ` or go on the terminal tab and open it.
  2. You can see there are a few tabs and icons.
  3. At the top right there would be a symbol 'v' beside the + sign from there select cmd and you are good to go.
  4. Example: tsc file.ts (here file is the name of the file you want to compile)
  5. As soon as you execute the above command you will get a javascript file, in this case, file.js will be generated...

Hope your issue would be solved...happy coding

Comments

-1

Go to C:\Users\user_name\AppData\Roaming\npm and remove tsc.ps1.

1 Comment

This does not provide an answer to the question. Once you have sufficient reputation you will be able to comment on any post; instead, provide answers that don't require clarification from the asker. - From Review

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.