Björn Hjorth
Björn Hjorth

Reputation: 2888

This is not the tsc command you are looking for

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.

Upvotes: 73

Views: 58500

Answers (19)

Harshil Dudhat
Harshil Dudhat

Reputation: 1

For typescript ^5.1.x

  1. npm uninstall tsc
  2. npm intall rimraf typesript
  3. add this build command as in your package json: rimraf ./build && npx -p typescript tsc
  4. image for package josn
  5. npm run build

Upvotes: -1

LC1983
LC1983

Reputation: 238

I managed to fix this issue by deleting the node_modules folder, and re-running yarn install.

Upvotes: -1

Tim Smith
Tim Smith

Reputation: 11

I did which tsc then rm -rf /[path].

WORKED!!!! Finally

Upvotes: -1

I have to uninstall tsc from my package.json. It was not supposed to be there; the typescript lib is enough.

Upvotes: 0

Adrien Joly
Adrien Joly

Reputation: 5336

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

Upvotes: 5

Rahul gupta
Rahul gupta

Reputation: 69

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

 npm install -g typescript --force

Upvotes: 6

Gerd
Gerd

Reputation: 2603

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

Install the typescript module by:

npm install -D typescript

Upvotes: 5

Kvn CF
Kvn CF

Reputation: 993

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.

Upvotes: 98

Muhammad Bilal
Muhammad Bilal

Reputation: 107

  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.

Upvotes: 0

0x7927
0x7927

Reputation: 1

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

Upvotes: -1

Nati Kamusher
Nati Kamusher

Reputation: 741

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

npm uninstall -g typescript --force
npm install -g typescript --force

Upvotes: -1

Plvtinum
Plvtinum

Reputation: 317

This solved the issue for me:

npm uninstall typescript
npm uninstall tsc #local tsc package
npm install typescript -g

Upvotes: 4

Chinge Yang
Chinge Yang

Reputation: 1

tsc is typescript/bin/tsc, so must uninstall tsc first. [1] https://i.sstatic.net/mUK0o.png

Upvotes: -1

Vivek Ranjan
Vivek Ranjan

Reputation: 99

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

Upvotes: 9

shuckster
shuckster

Reputation: 5427

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.

Upvotes: 3

Alvaro Aquije
Alvaro Aquije

Reputation: 1

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)!

Upvotes: -1

Vineel Shah
Vineel Shah

Reputation: 1058

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.

Upvotes: 31

Prashen
Prashen

Reputation: 99

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

choco install typescript

Upvotes: -1

Björn Hjorth
Björn Hjorth

Reputation: 2888

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

Upvotes: 3

Related Questions