DEV Community

Signor_P
Signor_P

Posted on

Why would deleted files remain in the dist?

When working with TypeScript, you might have noticed something odd:

You delete a .ts file — but its compiled .js and .d.ts files are still hanging around in your dist/ folder... 🤨

If you're like me, your first instinct is:

“Wait... shouldn't tsc take care of this automatically?”

Unfortunately, no.


🤔 Why This Happens

The TypeScript compiler (tsc) compiles .ts files to .js, .d.ts, and .map.js, but it does not clean up old files. If you delete a source file, the compiled version stays in your output directory.

That leftover file might:

  • Still get imported
  • Cause your app to crash unexpectedly
  • Create hard-to-track bugs
  • Waste space, especially in limited environments

🛠️ The Fix: tsc-clear

To fix this, I built tsc-clear:
A lightweight Rust-powered CLI that automatically cleans up your dist/ folder by removing any compiled files (.js, .d.ts, .map.js) that no longer have a corresponding .ts file in your project.


✨ Key Features

  • 🧹 Auto-cleans stale files after compilation
  • Fast — written in Rust for high performance
  • ⚙️ No configuration needed — reads tsconfig.json to detect your outDir
  • 🪟 Windows only for now (cross-platform support planned)

📦 Install It Globally

npm install -g tsc-clear
Enter fullscreen mode Exit fullscreen mode

🚀 Example Usage

Update your package.json scripts like this:

{
  "scripts": {
    "start": "tsc && tsc-clear src && node dist/index.js"
  }
}
Enter fullscreen mode Exit fullscreen mode

tsc-clear runs after tsc and before node, ensuring that your output directory is clean and safe.


🧠 Why I Built It

I was working on a project where I kept removing and renaming files — and everything looked fine... until I ran the app and hit an error caused by a file I had deleted days ago 😵

The old .js file was still sitting in dist/, silently breaking everything.

After searching for a solution and finding nothing lightweight, native, and easy to use — I decided to build tsc-clear for myself.

Now I’m sharing it with you. ✨


✅ TL;DR

  • TypeScript doesn't clean up dist/
  • Old files can break your app or cause unexpected behavior
  • tsc-clear solves this in one command

🔗 Links


Thanks for reading!
Let me know if this tool helped you — or drop a star ⭐ on GitHub if you like it!
Happy coding! 🧼💻

Top comments (0)