TypeScript command 'tsc' not running in Terminal and PowerShell

Note: this article is published on 10/05/2024.

This series of articles will discuss a specific feature for PowerShell programming. Actually, these two articles are talking to a same issue.

A: Introduction

This article will discuss,

  • A: Introduction
  • B: What --- What is the Issue 
  • C: Why --- What is the Reason
  • D: How to Fix:

B: What the issue is

When we run a typescript version checking command, 

tsc -v

We may get error in either PowerShell prompt or Visual Studio or VS Code terminal, such as

However, if we run this same command from a command line prompt, such as Windows Colose, we can get the result:

We can see something like this

TypeScript Not Running in terminal - Code with Mosh Forum

C: Why --- What is the Reason

There are some articles to discuss this issue, but most of them went to a wrong answer, such as

  • Typescript is not installed globally [ref]
  • user's PATH variable issue [ref]

Actually, it is not true. From the PowerShell window, we can see:

Read the article from Microsoft about_Execution_Policies - PowerShell | Microsoft Learn, This is due to PowerShell's execution policy. Go to the link as indicated https:/go.microsoft.com/fwlink/?LinkID=135170 that

The execution policy isn't a security system that restricts user actions. For example, users can easily bypass a policy by typing the script contents at the command line when they cannot run a script. Instead, the execution policy helps users to set basic rules and prevents them from violating them unintentionally.

Such as

The default for local Machine is Restricted

That is the reason that we cannot run the 'tsc' command from PowerShell or Visual studio and VS code terminal.

D: How to Fix:

Set it to ByPass:

You must be an admin role when opening the prompt:

or

References:


Similar Articles