Can't find Typescript compiler: Command "tsc" is not valid

JavascriptVisual Studio-2012TypescriptTsc

Javascript Problem Overview


Just installed Typescript extension to VS2012 and followed Install TypeScript for Visual Studio 2012 and then the tutorial to call the compiler:

> tsc greeter.ts

But when i try to compile .ts file where should i type: tsc greeter.ts? Tried it in VS command line and in windows console, always get the message that tsc is not recognized as command(Command "tsc" is not valid.).

Javascript Solutions


Solution 1 - Javascript

If you're using tsc as a node module, make sure you've installed it with

npm install -g typescript

Then it should be available globally in your node command prompt

Solution 2 - Javascript

Ensure you have,

> C:\Program Files (x86)\Microsoft SDKs\TypeScript\0.8.0.0

or,

> C:\Program Files\Microsoft SDKs\TypeScript\0.8.0.0

on your path. If not, try restarting CMD.EXE and see if shows up with a fresh copy. If that fails, try adding one of the above manually to your path.

Solution 3 - Javascript

For folks on Windows with Visual Studio Code, who don't want to install full Visual Studio just for tsc.exe, I can suggest to simply download it from here: https://www.microsoft.com/en-us/download/details.aspx?id=48593.

This is a shame that this link is missing from the TypeScript download page.

Although the installer is called TypeScript for Visual Studio 2015, it works with Visual Studio Code as well.

After you downloaded and installed TypeScript, you should manually add its installation directory (C:\Program Files (x86)\Microsoft SDKs\TypeScript\2.0\ in my case) to the %PATH% environment variable.

Open environment variables editor:

Win + S; e, n, v, i, r, o; click Edit environment variables for your account.

In the window opened find Path user variable (note that it is not named %PATH% here, but still this is it). You probably have some path set there already. You just have to type ;, append the TypeScript install location and add one more ; in the end.

Screenshot for your reference:

enter image description here

After this is done, open Command Prompt and type in tsc -v. If tsc.exe's version is getting displayed, you're done. For this to work, restart Command Prompt and VS Code after making the change to the %PATH%.

P.S. If you get "error TS5057: Cannot find a tsconfig.json file at the specified directory: '.'", just create tsconfig.json file in the document root (that's probably where your .ts files are) with simple contents: {}. This means "an empty JSON file <...>. This will be sufficient for most people." (source).

Solution 4 - Javascript

Usually closing and reopen the command prompt solves the issues.

Solution 5 - Javascript

Check both of these folders to find out what TypeScript version you have:

C:\Program Files (x86)\Microsoft SDKs\TypeScript\
C:\Program Files\Microsoft SDKs\TypeScript\

Right-click the folder showing the version number then 'copy as path'.

Paste this into your system path (quick access - Windows key then type 'env'). Then open a new command prompt console as administrator and 'tsc' should work.

Solution 6 - Javascript

As new path variable, don't use the displayed tsc version number but the TypeScript Folder Name which is different.

Sample :

tsc -v display 2.4.1 

but TypeScript directory is

>C:\Program Files (x86)\Microsoft SDKs\TypeScript\2.4

Solution 7 - Javascript

Just delete AppData\Roaming\npm\tsc.ps1 file and the issue will be fixed.

Solution 8 - Javascript

In CMD type where tsc if it doesn't show a path like this C:\Program Files (x86)\Microsoft SDKs\TypeScript\typescript version you installed\ it means your tsc is not running from here.You need to change the environment path manually by following @TranslucentCloud 's answer .

Solution 9 - Javascript

In my case, I did install typescript globally by using -g flag but tsc was not recognized. It turns out that below directory was not included in path environment variable:

C:\Users\Jitendra\AppData\Roaming\npm

Adding this directory to path variable worked for me.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Question0x49D1View Question on Stackoverflow
Solution 1 - JavascriptlhkView Answer on Stackoverflow
Solution 2 - JavascriptchuckjView Answer on Stackoverflow
Solution 3 - JavascriptNeurotransmitterView Answer on Stackoverflow
Solution 4 - JavascriptLaszloView Answer on Stackoverflow
Solution 5 - JavascriptChris HalcrowView Answer on Stackoverflow
Solution 6 - JavascriptVinamisView Answer on Stackoverflow
Solution 7 - JavascriptSagnik GhoshView Answer on Stackoverflow
Solution 8 - JavascriptShahriar MorshedView Answer on Stackoverflow
Solution 9 - JavascriptJitendra KumarView Answer on Stackoverflow