DEV Community

Cover image for How to force TypeScript’s tsc to rebuild your files
Paul Walker
Paul Walker

Posted on • Originally published at solarwinter.net on

How to force TypeScript’s tsc to rebuild your files

I’ve noticed when using tsc in watch mode that sometimes - especially if a file has been renamed - it doesn’t realise the file needs recompiling. This state persists across reboots, restarting the watcher, all the usual stuff.

The last time I hit this was when I needed to re-order the seed files I’m using for this project. A file that had been last needed to be first, everything had to move around as I use numbers in the filenames to ensure the seeding order is clear. Mostly it works really well.

Renaming the files wasn’t a problem, but suddenly the lib/seeds directory has two sets of seeds in. The results from that - as you’d expect - were not good.

rm lib/seeds/*, re-run and … nothing. Hmm.

Maybe it needs prompting to recompile them? touch src/seeds/* and still nothing.

Last time this happened I rebooted the laptop and everything. This time, thankfully, I remembered before I got that far.

The only solution I’ve found? Delete tsconfig.tsbuildinfo and rebuild. From the filename I assume it seems caches the build info in that file, which is entirely reasonable. It just doesn’t always figure out when the cache is out of date.

Hope that saves someone a few reboots and some time.

Top comments (0)