vite-plugin-dts-build
raw JSON → 0.2.3 verified Mon Apr 27 auth: no javascript
A Vite plugin for building .d.ts declaration files using a worker thread with incremental compilation for performance. Currently at v0.2.3, released January 2025. It supports optional dual ESM/CJS output for libraries, source maps, and improved error reporting. Compared to alternatives like vite-plugin-dts, it focuses on speed via worker-based incremental builds and explicit control over format redirection. Requires TypeScript and Vite as peer dependencies. The plugin is under active development with frequent updates.
Common errors
error Error: Cannot find module 'vite-plugin-dts-build' ↓
cause Package not installed or missing from dependencies.
fix
Run
npm install vite-plugin-dts-build --save-dev and ensure it's in devDependencies. error TypeError: vitePluginDtsBuild is not a function ↓
cause Incorrect import (named instead of default) or CJS require with wrong name.
fix
Use default import:
import vitePluginDtsBuild from 'vite-plugin-dts-build' error Error: The 'dtsForCjs' option requires 'rollupTypes' to be true ↓
cause Incompatible plugin options: dtsForCjs without rollupTypes.
fix
Set
rollupTypes: true when using dtsForCjs: true. error Error: Worker thread exited unexpectedly ↓
cause TypeScript or plugin error causing worker crash.
fix
Check TypeScript configuration and ensure no syntax errors; set
onError: 'warn' for debugging. error Module not found: Can't resolve '@/components/...' in ... ↓
cause Path alias not resolved in type declarations.
fix
Configure path aliases in Vite's resolve.alias and ensure they match tsconfig paths.
Warnings
breaking In v0.2.0, error behavior changed: instead of stopping on first error, all errors are printed. This may break CI scripts that expect immediate exit. ↓
fix Update CI to handle multiple errors or set `onError: 'fail'` if available (check docs).
deprecated In future versions, the `rollupTypes` option may be renamed. See changelog for v0.2.0. ↓
fix Monitor changelog and migrate to new option name when released.
gotcha Dual mode (dtsForCjs) creates a package.json redirect for Node10 resolution. This may cause unexpected behavior if your project uses older Node.js or custom resolution. ↓
fix Ensure Node.js >=12 or disable dtsForCjs.
gotcha The plugin uses a worker thread. Ensure your build environment supports worker_threads (Node >=12). ↓
fix Use Node.js 12+ or add fallback worker polyfill.
Install
npm install vite-plugin-dts-build yarn add vite-plugin-dts-build pnpm add vite-plugin-dts-build Imports
- vitePluginDtsBuild wrong
const vitePluginDtsBuild = require('vite-plugin-dts-build')correctimport vitePluginDtsBuild from 'vite-plugin-dts-build' - vitePluginDtsBuild wrong
import { vitePluginDtsBuild } from 'vite-plugin-dts-build'correctimport { default as vitePluginDtsBuild } from 'vite-plugin-dts-build' - type PluginOptions
import type { PluginOptions } from 'vite-plugin-dts-build'
Quickstart
// vite.config.ts
import { defineConfig } from 'vite';
import vitePluginDtsBuild from 'vite-plugin-dts-build';
export default defineConfig({
plugins: [
vitePluginDtsBuild({
// Enable for library dual output (ESM + CJS)
rollupTypes: true,
dtsForCjs: true,
}),
],
});