This is not the tsc command you are looking for

avatar

Borislav Hadzhiev

Last updated: Mar 26, 2022

banner

Photo from Unsplash

This is not the tsc command you are looking for #

To solve the error "This is not the tsc command you are looking for", uninstall the tsc package by running npm uninstall tsc and run the tsc command with the --package flag, e.g. npx --package typescript tsc --init.

this is not tsc command you are looking for

Open your terminal in your project's root directory and run the following commands:

shell
npm uninstall tsc npm uninstall -g tsc npx --package typescript tsc --init npx --package typescript tsc --version
The first thing we did is uninstall the tsc package because it is a completely different package.

Notice that we used the --package flag to specify the correct typescript package in the commands above.

Alternatively, you can install typescript globally by running the following command.

shell
# 👇️ install typescript globally npm install typescript@latest -g # 👇️ generate tsconfig.json file tsc --init # 👇️ get typescript version tsc --version

Now you are able to use the correct tsc command without having to prefix it with npx and use the --package flag.

If the global installation of typescript fails, you might have to run the command prefixed with sudo.
shell
# 👇️ If you got permissions error, run with sudo sudo npm install typescript@latest -g tsc --init tsc --version

If you are able to run the tsc --version command and get the version number of the typescript package, then the installation has succeeded.

You can open your package.json file and make sure you don't have the tsc package installed in your dependencies or devDependencies objects, because it is a deprecated package that you shouldn't be using.

Once you have typescript installed globally, the tsc command will refer to the TypeScript compiler.

Here are some common commands you could use.

shell
# Run a compile based on a backwards look through the fs for a tsconfig.json tsc # Initializes a TypeScript project and creates a tsconfig.json file tsc --init # Watch input files tsc --watch # Show the compiler's version tsc --version # Emit JS for just the index.ts with the compiler defaults tsc index.ts # Emit JS for any .ts files in the folder src, with the default settings tsc src/*.ts # Emit files referenced in with the compiler settings from tsconfig.production.json tsc --project tsconfig.production.json # Emit d.ts files for a js file with showing compiler options which are booleans tsc index.js --declaration --emitDeclarationOnly # Emit a single .js file from two files via compiler options which take string arguments tsc app.ts util.ts --target esnext --outfile index.js

A helpful command you can use for debugging is tsc --all, which shows all of the options.

Alternatively, you can look for the syntax of the command and the available options in the tsc cli reference.

Conclusion #

To solve the error "This is not the tsc command you are looking for", uninstall the tsc package by running npm uninstall tsc and run the tsc command with the --package flag, e.g. npx --package typescript tsc --init.

I wrote a book in which I share everything I know about how to become a better, more efficient programmer.
book cover
You can use the search field on my Home Page to filter through all of my articles.