Incremental compilation: should editing tsconfig.json invalidate the .tsbuildinfo cache in watch mode?
0 reputation · 08 Dec 2020, 11:50 UTC
0 reputation · 08 Dec 2020, 11:50 UTC
With "incremental": true in tsconfig.json, TypeScript writes a .tsbuildinfo file that records the module graph and emit state. In tsc --watch, this lets the compiler skip re-emitting unchanged files, so retries after a failed or partial run do not produce duplicate writes to the output directory.
The behavior I want to pin down is the compatibility boundary around configuration changes. My understanding is that editing tsconfig.json itself — for example adding a compiler option — does not invalidate the incremental cache while a watcher is running, and a rebuild only happens after restarting the watcher or deleting the .tsbuildinfo file. With tsc --build and project references, config changes appear to be handled differently.
There are also related edge cases: noEmitOnError can suppress output in a way that looks like a missing write, and outFile bundling rewrites the entire bundle on any change, losing the fine-grained skip behavior.
Is the lack of automatic cache invalidation on tsconfig.json edits an intentional design decision or a known gap? Is there a documented way to force invalidation without deleting .tsbuildinfo manually? Does the answer differ between plain --watch and --build --watch?
With current versions of the TypeScript compiler, a change to tsconfig.json while tsc --watch is running automatically forces a full recompilation of the program. The incremental state stored in .tsbuildinfo is considered stale and is discarded. The same applies to --build --watch; the build system marks the affected project (and any dependents) as out‑of‑date and rebuilds them.
The compiler keeps the compilerOptions that were in effect when .tsbuildinfo was written. On startup or when the config file changes, the current options are compared with the stored ones. If any option differs, the incremental data is ignored and a new program graph is built from scratch. This logic is part of the core watchHost implementation.
tsc --watchtsconfig.json as a normal file..tsbuildinfo is not reused.tsc --build --watch.tsbuildinfo.tsconfig.json and marks the project as dirty.noEmitOnError simply suppresses output when errors exist; it does not affect the cache.outFile is used, the entire bundle is regenerated on any change, which is expected behavior.# Full rebuild in build mode
$ tsc --build --force
# Clean all incremental data
$ tsc --build --clean
These commands are the documented ways to invalidate the cache programmatically.
tsc --watch --extendedDiagnostics and note the files emitted.target) in tsconfig.json..tsbuildinfo JSON to confirm that the stored compilerOptions differ from the current ones.To tailor the recommendation more precisely, could you tell me which TypeScript version you are running (e.g., tsc --version)? Older releases pre‑3.x had a known gap where config edits were ignored in watch mode.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.