How to fix tsc command expects a TypeScript file in TypeScript
The TypeScript compiler is telling you that it cannot compile anything because you either ran `tsc` without a tsconfig/project or you pointed it at files that are not TypeScript sources.
Quick fix
Fixes tsc command expects a TypeScript file
npx tsc --init- Create or reuse a tsconfig.json for the directory you are compiling
- Pass explicit TypeScript source files when no tsconfig exists
- Run the compiler from the directory that owns the tsconfig
- Include JavaScript sources or restrict file matching as needed
npx tsc --inittsc command expects a TypeScript file
npx tsc --initWhat this error means
tsc either reads a tsconfig.json in the current directory or accepts explicit file paths. When neither is supplied, the CLI cannot build anything and prints "tsc command expects a TypeScript file" to remind you that it needs at least one `.ts`, `.tsx`, `.cts`, `.mts`, or `.d.ts` input.
Typical symptoms
- The CLI exits immediately with the message `tsc command expects a TypeScript file` and no emitted files.
- Build scripts stop before emitting JavaScript because the compiler refuses to run.
- CI or tooling that invokes `npx tsc` reports failure even though TypeScript files exist elsewhere in the repo.
- No diagnostic errors about source code are shown because the compiler never started.
Common causes
- You ran `tsc` in a folder that has no tsconfig.json and did not pass any `.ts`/`.tsx` files.
- A script calls `tsc` with the wrong argument (for example a directory or `.js` file) instead of TypeScript source.
- The project uses a tsconfig located outside the current working directory, so `tsc` cannot find it.
- Tooling (IDE pre-launch task, npm script, CI job) sets the working directory incorrectly before invoking `tsc`.
- The package contains only JavaScript but `tsc` is run without `allowJs`, so it treats the compilation as empty.
How to fix "tsc command expects a TypeScript file"
Run the compiler initialization tool to scratch a tsconfig in the folder where you expect to build from:
npx tsc --initIf the project already has a configuration file, make sure you run tsc from the directory that contains that tsconfig or explicitly pass its path with tsc -p path/to/tsconfig.json.
You can compile individual files without a config by giving them on the CLI:
npx tsc src/index.ts src/lib/util.tsUse .ts, .tsx, .cts, or .mts extensions and avoid directories or JavaScript-only files so that the compiler sees valid input.
TypeScript walks up from your current working directory to find a tsconfig.json. If you operate inside a subfolder, change into the parent or tell the compiler exactly where the config lives:
cd packages/widget
npx tsc
# or
npx tsc -p ../tsconfig.base.jsonThis ensures the compiler does not exit before reading compiler options.
If the repository only contains JavaScript and you rely on allowJs, flip on the compiler option or add TypeScript files so the input set is not empty:
{
"compilerOptions": {
"allowJs": true,
"include": ["src/**/*"]
}
}Otherwise, add a .ts entry (even an empty shim) to give tsc something to compile.
Check npm scripts, CI tasks, and IDE pre-launch commands so they change into the right folder or pass the -p flag. A script that calls npx tsc before building the workspace might run in the repo root while the tsconfig lives in packages/app. Adjust the command or script to match the project layout.
Advanced notes
When no tsconfig exists and you do not specify source files, TypeScript prints this message instead of verbose diagnostics. The CLI looks in the working directory and each parent for tsconfig.json, and once it finds one it compiles the files specified by the "files", "include", or "extends" clauses. For monorepos or nested packages, keep a tsconfig in each package and always run tsc -p from inside the package, or create a top-level tsconfig.build.json and compile it with npx tsc -p tsconfig.build.json.
Frequently asked questions
- What does "tsc command expects a TypeScript file" mean?
- json in the current directory or accepts explicit file paths. ts input.
- How do I fix "tsc command expects a TypeScript file"?
- The TypeScript compiler is telling you that it cannot compile anything because you either ran tsc without a tsconfig/project or you pointed it at files that are not TypeScript sources.
- What causes "tsc command expects a TypeScript file"?
- You ran tsc in a folder that has no tsconfig.json and did not pass any .ts/.tsx files. A script calls tsc with the wrong argument (for example a directory or .js file) instead of TypeScript source. The project uses a tsconfig located outside the current working directory, so tsc cannot find it.
- Is the "tsc command expects a TypeScript file" error serious?
- It is a low-severity error โ more of a blocker than a risk. The steps above resolve it.
Official resources & further reading
- ๐TypeScript Official Documentation
- ๐TypeScript: tsconfig.json reference(Official Docs)
- ๐TypeScript: Compiler options & CLI(Official Docs)
- ๐TypeScript: tsc command usage(Official Docs)