tsup --dts: Bundle a Library With Types
tsup src/index.ts --dts bundles a TypeScript library with esbuild and generates .d.ts type declarations alongside it.
tsup wraps esbuild for library authors: fast bundling in multiple formats plus type declarations, which is exactly what a publishable package needs from CI.
What it does
tsup bundles the given entry with esbuild and, with --dts, runs a separate declaration pass (via rollup-plugin-dts) to produce a single .d.ts. --format controls whether it emits ESM, CJS, or both.
Common usage
tsup src/index.ts --dts --format esm,cjs
tsup src/index.ts --dts --clean --minify
# entry and options in tsup.config.ts, just run
tsupOptions
| Flag | What it does |
|---|---|
| --dts | Generate .d.ts declaration files |
| --format <f> | Output formats: esm, cjs, iife (comma-separated) |
| --clean | Empty the output directory before building |
| --minify | Minify the output |
| --sourcemap | Emit source maps |
| --target <t> | Compilation target, e.g. es2020, node18 |
| -d, --out-dir <dir> | Output directory (default dist) |
In CI
The --dts pass uses your tsconfig and can be far slower than the bundle pass, so it dominates library build time. Keep declarations passing by running tsc --noEmit as a separate typecheck gate; tsup --dts surfaces the same errors but later.
Common errors in CI
The declaration pass reprints tsc errors like "error TS2307: Cannot find module ..." when a type dependency is missing. "Cannot find module \"typescript\"" means TypeScript is not installed but --dts requires it. If --dts hangs or OOMs on a big library, split entries or raise NODE_OPTIONS=--max-old-space-size.