Repository navigation
"tsc --project tsconfig.json --incremental" doesn't clean files from output folder. #36648
Description
Activity
tsc --build --cleanwill only clean the files that are the outputs from current program so if you changed the name of the file or there exists some old file that's not part of the project' its output wont be deleted. For now this is by design and we do not track files that aren't part of compilation- addedQuestionAn issue which isn't directly actionable in codeAn issue which isn't directly actionable in code
on Feb 6, 2020 typescript-bot commented
on Feb 11, 2020 ContributorMore actionsThis issue has been marked as 'Question' and has seen no recent activity. It has been automatically closed for house-keeping purposes. If you're still waiting on a response, questions are usually better suited to stackoverflow.
It's because of VS Code's integrated Git support.
A right-click
Renamedoes agit mv(git rm --cached+mv+git add).Our TypeScript compiler only sees working directory changes, i.e.
mvchanges in ouroutDir, whereasgit addis where Git will automatically detect the move/rename.Both being by Microsoft, it would be nice to see relevant Git support in our compiler presumably before looking at other VCS's.
For now this is by design and we do not track files that aren't part of compilation
Makes sense, and this makes it possible to output JS and declaration files as siblings to the input TS files, which is a valid use case.
Maybe there can be an option for it though? f.e.
cleanNonOutputFilesFromProjectOutput: trueor some descriptive name like that.Reacted by Nitsan Avni, Roy Razon, Lex Kuncevic, Jelle Roets and Tomas ReimersThis happens not only in --incremental mode.
Sheetal Nandi (@sheetalkamat) I suppose someone somewhere if going to accidentally publish files they didn't mean to publish.
Reacted by Alon MizrahiSheetal Nandi (@sheetalkamat) Ryan Cavanaugh (@RyanCavanaugh) can't the
.tsbuildinfofile be utilized to only delete output files corresponding to the source files from the previous build that are no longer present? Seems like a pretty reasonable and straightforward use of.tsbuildinfo.Not having this automatic cleanup has at least two pretty bad implications:
- As Joe Pea (@trusktr) mentioned, leftover output files could be published accidentally
- Project references are broken in monorepos (see the extensive discussion starting here in Project-references type check with --noEmit fails without built files #40431)
It looks like using a third-party tool like Google's Wireit (see its dedicated TypeScript recipe) is right now the only viable way to avoid these problems.
- locked as resolved and limited conversation to collaborators
on Oct 21, 2025
TypeScript Version: 3.7.5
Search Terms:
tsc incremental doesn't clean old files
Code
N/A
Expected behavior:
When, for example, refactoring by renaming a file (and VS Code updates all import statements, etc), then the outputDir should not contain the old file.
Actual behavior:
The output directory contains old unused files.
Prior to trying incremental builds (today for the first time) I was simply doing
rm -rf dist/to "clean" it first. This doesn't work with incremental builds (#30602).I tried running
tsc --build --cleanandtsc --build ./tsconfig.json --cleanbut those don't do anything, old files still remain in the output folder.Note, I have a single tsconfig.json at the root of my project, and compile all my source code into a single output directory all at once with a single
tsccommand. I'm not "composing projects".Playground Link:
N/A
Related Issues: