The shell says tsc is not found after installing TypeScript
tsc: command not foundShort answer
tsc is a program that the typescript package installs. A local install puts it in node_modules/.bin, which your shell does not search, while a global install links it into npm's bin folder, which must be on PATH. Install it, then run it with npx or an npm script.
Fix it fast
1Find out which cause you have
See whether the project already holds the compiler in its local bin folder.
ls node_modules/.bin/tsc2Match what you see, then jump to its fix
- 1
ls node_modules/.bin/tsc reports no such fileTypeScript is not installed in the projectFix - 2
ls node_modules/.bin/tsc shows the file, yet tsc alone is not foundIt is installed locally, and you typed tsc in the shellFix - 3
npm install -g typescript succeeded, a new shell still cannot find tscInstalled globally, but npm's bin folder is not on PATHFix
- 1
What does the error look like?
tsc: command not found
Cause 1 of 3
TypeScript is not installed in the project
1Check
Look for typescript in the dependencies.
grep -n "typescript" package.json2Fix
Install it as a dev dependency, then run it through npx.
npm install typescript --save-dev
npx tsc --version3Verify
npx should print the compiler version.
npx tsc --versionConfirmed by docs.npmjs.com
Cause 2 of 3
It is installed locally, and you typed tsc in the shell
1Check
npm places local executables in ./node_modules/.bin so that npm scripts find them. The shell does not look there. npx puts locally installed bins on the PATH of the command it runs.
ls -l node_modules/.bin/tsc2Fix
Call it with npx, or add a script to package.json and run that.
npx tsc
# package.json
"scripts": { "build": "tsc" }
npm run build3Verify
The build should run and write its output.
npm run buildConfirmed by docs.npmjs.com
Cause 3 of 3
Installed globally, but npm's bin folder is not on PATH
1Check
npm links global executables into the bin folder under its prefix, and the docs say that folder must be in your terminal's PATH. On Unix it is prefix/bin; on Windows it is the prefix itself.
echo $PATH2Fix
Add the folder to PATH in your shell profile, open a new terminal and try again. For team projects a local install is easier to repeat.
npm install -g typescript3Verify
Open a new terminal and check the version.
tsc --versionConfirmed by docs.npmjs.com
How do I stop it coming back?
- Keep typescript in devDependencies and call it only from npm scripts or npx, so every machine uses the same version.
- Add a build script to package.json instead of documenting a bare tsc command.
- Commit the lockfile so CI installs the same compiler.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
- TaxiDexMy own multi-tenant taxi dispatch SaaS: API, dispatcher portal, driver and passenger apps, and the servers underneath.
- QistLockA NestJS and React SaaS driving an Android Device Owner agent that locks financed phones when payments lapse.
- WorkforceA field app, an admin console and a self-hosted Node.js server for push and reconciliation.
Related fixes
Back end
TypeScript cannot find '@angular/platform-browser' in an Angular project
Cannot find module '@angular/platform-browser' or its corresponding type declarations.
TS2307 means TypeScript could not turn the import into a file.
3 causes, each with a fixBack end
Angular build fails with TS2707 or "has no exported member" after installing a library
Module '"@angular/core"' has no exported member
These errors mean a library was compiled by a newer Angular than your app uses.
3 causes, each with a fixBack end
Application Load Balancer returns 502 for a Node.js target
HTTPCode_ELB_502_Count
An ALB returns 502 when the target gives it something it cannot use: a refused or reset connection, a connection closed mid-request, a bad response, or a header over 32 K.
4 causes, each with a fixBack end
cdk synth says --app is required
--app is required either in command-line, in cdk.json or in ~/.cdk.json
The CDK CLI needs a command that runs your app and finds it in three places: the --app option, cdk.json in the project folder, or cdk.json in your home folder.
3 causes, each with a fixBack end
TypeScript cannot find module '@nestjs/core' or its type declarations
error TS2307: Cannot find module '@nestjs/common' or its corresponding type declarations.
TS2307 means TypeScript searched node_modules and found neither the package nor its types.
3 causes, each with a fixBack end
Mocha or Node cannot find ts-node/register
Error: Cannot find module 'ts-node/register'
Node resolves ts-node/register from your project's node_modules, so the package must be installed there, next to typescript.
2 causes, each with a fix