Registry / devops / vite-plugin-dts

vite-plugin-dts

JSON →
library4.5.4jsnpmunverified

vite-plugin-dts is a Vite plugin that generates TypeScript declaration files (.d.ts) from your source code during the build process. Current stable version is 4.5.4, with frequent releases. It integrates with both TypeScript's built-in compiler and vue-tsc for Vue SFC support. Key differentiators include support for bundling declarations via @microsoft/api-extractor, path alias resolution, and a flexible plugin system with hooks like afterBootstrap. It is the de facto standard for declaration generation in Vite projects, actively maintained with a strong focus on compatibility and performance.

npm install vite-plugin-dts
INSTALL
IMPORT
SIG · VITE-PLUGIN-DTS
V
vite-plugin-dts
devopsjavascriptv4.5.4
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

vite-plugin-dts
import dts from 'vite-plugin-dts'
const dts = require('vite-plugin-dts')
Default export; ESM-only. CommonJS require() will fail in some environments.
vitePluginDts
import dts from 'vite-plugin-dts'
import { vitePluginDts } from 'vite-plugin-dts'
The default export is the plugin function. Named exports include types only.
PluginOptions
import type { PluginOptions } from 'vite-plugin-dts'
import { PluginOptions } from 'vite-plugin-dts'
PluginOptions is a type, use import type for correctness.

Shows the basic configuration of vite-plugin-dts in a Vite config file. Includes include, outDir, and optional bundleTypes.

import dts from 'vite-plugin-dts' import { defineConfig } from 'vite' export default defineConfig({ plugins: [ dts({ include: ['src/**/*.ts'], outDir: 'dist', // Optional: enable declaration bundling // bundleTypes: true }) ] }) // Then run 'vite build' to generate .d.ts files
Debug
Known issues
deprecatedThe 'beforeBundle' hook has been deprecated in v5.0.0-beta. Use 'afterBootstrap' instead.
fix
Replace 'beforeBundle' with 'afterBootstrap' in the plugin options.
affects: >=5.0.0-beta.0
breakingIn v5.0.0, the plugin no longer supports CommonJS require() directly; it is ESM-only.
fix
Switch to ESM imports: import dts from 'vite-plugin-dts'
affects: >=5.0.0
gotchaIf using TypeScript path aliases, you must configure the 'tsconfigPath' option to match the resolved path.
fix
Set 'tsconfigPath' to the correct tsconfig file path, e.g., 'tsconfig.json'.
affects: >=1.0.0
gotchaThe plugin may generate duplicate declarations if 'include' overlaps with resolved 'tsconfig' includes.
fix
Specify a more precise 'include' pattern, e.g., exclude 'test' or 'stories'.
affects: >=1.0.0
Errors
Common errors & fixes
Error: [vite-plugin-dts] Failed to resolve module specifier './some-module'
The plugin cannot resolve a module path that uses aliases not defined in TypeScript paths.
fix
Ensure your tsconfig has the correct 'paths' mapping and set 'tsconfigPath' option to the correct config.
TypeError: dts is not a function
Using default import incorrectly, or the plugin version does not support the import style being used.
fix
Use 'import dts from 'vite-plugin-dts'' with ESM, and ensure the package is installed and not a type-only export.
Cannot find module 'vite-plugin-dts' or its corresponding type declarations.
Package not installed or TypeScript resolution not aware of the module.
fix
Run 'npm install -D vite-plugin-dts' and ensure tsconfig 'types' includes 'vite/client' if needed.
The 'rollupTypes' option is deprecated. Use 'bundleTypes' instead.
Using an older option name from a previous version.
fix
Replace 'rollupTypes: true' with 'bundleTypes: true' in the plugin options.
Upgrade
Version history
4.5.4latest on npm
Audit
Dependencies
viterequiredpeer dependency - the plugin works as a Vite plugin
typescriptrequiredpeer dependency - required for type generation
Agent activity
27 hits · last 30 days
node
12
OpenAI (training)
1
Resources
vite-plugin-dts — npm install vite-plugin-dts · libregistry