TypeScript Reference ยท tsconfig: Projects, Files and Watch Options
TypeScript explainFiles option
Reference for the TypeScript explainFiles option: list each file in the program with the reason it was included, to debug slow or oversized builds.
explainFiles prints every file in the program together with the reason or reasons it was included. Typical reasons: the file matched an include pattern, it is a root file named on the command line, another file imported it, or a library or type reference pulled it in.
It is the tool to reach for when a build includes files you did not expect, such as test files in production output or thousands of declaration files from node_modules/@types. It does not change the program.
tsc --noEmit --explainFiles
Try it
Real output contains your absolute paths, so these examples model the reasons as data.
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or readFileSync(0)), it gets the next line from this box.
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or readFileSync(0)), it gets the next line from this box.
Syntax
{ "compilerOptions": { "explainFiles": true } }
tsc --explainFiles
Output shape: a file path line followed by indented reason lines. Common reason texts include "Root file specified for compilation", "Matched by include pattern '...' in 'tsconfig.json'", "Imported via '...' from file '...'", "Library '...' referenced via 'lib' from file ...", and "Entry point for implicit type library '...'".
Usage notes
- Pair with
--noEmitto inspect without writing files. - Unexpected
@typespackages show an "implicit type library" reason; restrict them with thetypesoption. - A reason chain, not a cause. A file imported by an imported file lists only its direct importer.
- Broad
includepatterns such as**/*are the most common source of surprise; narrow them or addexclude. - Combine with
listFileswhen you only need the plain list, and withtraceResolutionwhen the question is how an import was resolved. - Output is long. Redirect it to a file and search.