esbuild-plugin-d.ts

raw JSON →
2.0.0 verified Mon Apr 27 auth: no javascript

ESBuild plugin for compiling TypeScript declaration files (.d.ts) using the TypeScript compiler API. Current stable version is 2.0.0, released in late 2024. Requires Node.js >=20 and TypeScript >=5.5 <7. Key differentiator: integrates declaration generation directly into esbuild's build pipeline, supporting incremental builds and experimental bundling. v2 removed default export, Node.js <20 support, and deprecated helper exports. Alternatives include tsup and separate tsc --emitDeclarationOnly.

error Cannot find module 'esbuild-plugin-d.ts'
cause Incorrect import: using default import in v2.
fix
Use named import: import { dtsPlugin } from 'esbuild-plugin-d.ts'
error TypeError: dtsPlugin is not a function
cause Trying to call default export in v2.
fix
Change to import { dtsPlugin } from 'esbuild-plugin-d.ts'
error The requested module 'esbuild-plugin-d.ts' does not provide an export named 'default'
cause Default export removed in v2.
fix
Use named export dtsPlugin.
error error TS2693: 'DtsPluginOptions' only refers to a type, but is being used as a value here.
cause Using `DtsPluginOptions` as a runtime value instead of a type import.
fix
Use import type { DtsPluginOptions } from 'esbuild-plugin-d.ts'
breaking Default export removed in v2. Use named export `dtsPlugin`.
fix Change `import dtsPlugin from 'esbuild-plugin-d.ts'` to `import { dtsPlugin } from 'esbuild-plugin-d.ts'`
breaking Node.js <20 no longer supported in v2.
fix Upgrade Node.js to version 20 or later.
breaking TypeScript versions below 5.5 are no longer supported in v2.
fix Upgrade TypeScript to >=5.5.0 <7
deprecated Helper exports (e.g., `createProgram`) removed in v2.
fix Only use the plugin and DtsPluginOptions type.
gotcha Plugin adds noticeable overhead; consider separate `tsc --emitDeclarationOnly` if build time is critical.
fix Use tsc separately for declaration emit if esbuild integration is not required.
gotcha Declaration bundling (`experimentalBundling`) is experimental and may not cover all edge cases.
fix Test thoroughly or avoid production use.
gotcha Incremental builds require `incremental: true` in tsconfig.
fix Set `incremental: true` in your tsconfig.
npm install esbuild-plugin-d.ts
yarn add esbuild-plugin-d.ts
pnpm add esbuild-plugin-d.ts

Shows basic usage: importing the plugin and adding it to esbuild plugins array.

import { build } from 'esbuild';
import { dtsPlugin } from 'esbuild-plugin-d.ts';

await build({
  entryPoints: ['./src/index.ts'],
  outdir: './dist',
  plugins: [dtsPlugin()],
});