rollup-plugin-dts

raw JSON →
6.4.1 verified Mon Apr 27 auth: no javascript maintenance

A Rollup plugin for bundling .d.ts TypeScript definition files into a single file. Current stable version is 6.4.1, released under maintenance mode with occasional compatibility updates for new TypeScript releases. Key differentiators: leverages TypeScript's own compiler for import resolution, automatically externalizes node_modules and @types, supports sourcemaps for Go-to-Definition via declarationMap. Alternatives include API Extractor and dts-bundle-generator. Requires Node >=20, peer dependencies rollup ^3.29.4 || ^4 and TypeScript ^4.5 || ^5.0 || ^6.0.

error [!] TypeError: dts is not a function
cause Using default import or CommonJS require in Rollup config; the module exports a named function.
fix
Use import { dts } from 'rollup-plugin-dts' or use .mjs extension and named import.
error Error: Could not resolve 'some-module' from 'file.d.ts'
cause The plugin cannot find a module referenced in .d.ts file (likely not in node_modules).
fix
Ensure the module is installed or marked as external in tsconfig or plugin options.
error TypeError: Cannot read properties of undefined (reading 'program')
cause Missing or invalid tsconfig.json; plugin needs TypeScript project configuration.
fix
Create a tsconfig.json with appropriate settings or use the tsconfig option.
breaking Version 6 requires Node >=20 and TypeScript ^4.5 || ^5.0 || ^6.0. Older Node/TS versions incompatible.
fix Update Node to >=20, TypeScript to ^4.5+.
breaking Version 4 drops support for Rollup 2. Only Rollup ^3.29.4 || ^4 supported.
fix Upgrade Rollup to ^3.29.4 or ^4.
deprecated Default import is deprecated in favor of named import { dts }.
fix Use import { dts } from 'rollup-plugin-dts' instead.
gotcha Plugin automatically externalizes all node_modules, but external packages' .d.ts files are not bundled unless includeExternal option is set.
fix Use includeExternal option to bundle specific packages.
gotcha Using other resolution plugins (e.g., @rollup/plugin-node-resolve) can cause conflicts and is not recommended.
fix Do not use other Rollup plugins that modify module resolution.
npm install rollup-plugin-dts
yarn add rollup-plugin-dts
pnpm add rollup-plugin-dts

Basic Rollup configuration to bundle .d.ts files using the dts plugin. Input is .ts file, output is single .d.ts file.

// rollup.config.js
import { dts } from 'rollup-plugin-dts';

export default {
  input: './src/index.ts',
  output: {
    file: './dist/types/index.d.ts',
    format: 'es',
  },
  plugins: [dts()],
};