44

When I run tsc in the terminal (it does not matter where) I get returned:

$ npx tsc --version

                This is not the tsc command you are looking for


To get access to the TypeScript compiler, tsc, from the command line either:

- Use npm install typescript to first add TypeScript to your project before using npx
- Use yarn to avoid accidentally running code from un-installed packages

I do not have TypeScript installed globally to my knowledge so what I am expecting is that it can't find tsc.

mikemaccana
  • 110,530
  • 99
  • 389
  • 494
Björn Hjorth
  • 2,459
  • 5
  • 25
  • 31

15 Answers15

63

The problem in my case was that I had installed tsc package instead of the correct typescript. From https://www.npmjs.com/package/tsc:

Use typescript to get access to the tsc CLI command.

The fix is:

npm uninstall tsc
npm install -D typescript

Commands like npx tsc --version will still run because typescript provides the tsc executable.

Shlomo
  • 120
  • 2
  • 8
Kvn CF
  • 641
  • 5
  • 4
  • 5
    yep.. you need to install `typescript` package and not the `tsc` – AdityaParab Jul 24 '21 at 16:23
  • 2
    The fix is actually `npm uninstall tsc` and then `npm install typescript` (even if it was installed before, because during `tsc` uninstall the file `node_modules/.bin/tsc` gets removed no matter which package is was installed from). – Blade1336 Feb 01 '23 at 12:01
23

On my Mac, this fixed it:

npm uninstall -g typescript
npm install -g typescript

When I was fooling around trying to get started, i had done something like this:

npm install -g tsc   #bad, don't do this

which had screwed up my install.

Vineel Shah
  • 960
  • 6
  • 14
8

There is nothing to do as it's a very easy problem. Go to your vs code folder where you have installed node package. For example, in my system, it is:

C:\Users\vivekranjan\AppData\Roaming\npm

First of all you will notice that both the tscServer and tsc files are not created. So first delete all the tsc files, then go to the vs code and uninstall typeScript like this:

npm uninstall typescript

Then again install the typescript like this:

npm install -g typescript
Vivek Ranjan
  • 81
  • 1
  • 3
6

The tsc module is DEPRECATED! You only need the typescript module, if you need tsc!

Install the typescript module by:

npm install -D typescript
Benjamin Buch
  • 4,752
  • 7
  • 28
  • 51
Gerd
  • 2,265
  • 1
  • 27
  • 46
5

I had installed the old typescript compiler https://www.npmjs.com/package/tsc by mistake.

running where.exe tsc to find out what I was actually running suggested by @siddharth made me find the issue

Björn Hjorth
  • 2,459
  • 5
  • 25
  • 31
5

This solved the issue for me:

npm uninstall typescript
npm uninstall tsc #local tsc package
npm install typescript -g
Victor P
  • 1,496
  • 17
  • 29
Plvtinum
  • 187
  • 1
  • 5
  • 11
3

With typescript already installed both as a devDependency and globally, for me the solution was updating a package.json script:

Before:

{
  "scripts": {
    "build": "pnpx tsc ..."
  }
}

After:

{
  "scripts": {
    "build": "tsc ..."
  }
}

Perhaps everyone else knew that p/npx is not needed in scripts, but I didn't.

Hope this helps someone.

shuckster
  • 5,279
  • 2
  • 23
  • 22
3

if You are getting tsc command error just run it on your terminal

 npm install -g typescript --force
0

Try chocolatey manager for typescript installation https://community.chocolatey.org/packages/typescript

choco install typescript
Prashen
  • 101
  • 8
0

If using Volta or similar version managers you can do

npm remove -g typescript tic
pnpm remove -g typescript (if using pnpm)

and install it again with your node package manager of choice (globally)!

0

tsc is typescript/bin/tsc, so must uninstall tsc first. [1] https://i.stack.imgur.com/mUK0o.png

0

in my mac it worked only after adding 'force' flag to the command:

npm uninstall -g typescript --force
npm install -g typescript --force
Nati Kamusher
  • 533
  • 5
  • 9
0

go to tsc.cmd or tsc.ps1 path
look likes this

node_module
  typescript // remove this
  other...
tsc.cmd // remove this
other...

then

npm install -g typescript@latest
0x7927
  • 1
0
  1. First Run npm uninstall tsc, it will remove all the .bin/tcs folder.
  2. Then Run npm install typescript, it will fix the issue.
0

I avoid installing global dependencies, to keep my environment clean and deterministic.

=> I prefer to fix this problem by specifying the package that npx must use:

$ npx --package typescript tsc --version
Adrien Joly
  • 5,056
  • 4
  • 28
  • 43