{"id":20663,"library":"vite-plugin-dts","title":"vite-plugin-dts","description":"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.","status":"active","version":"4.5.4","language":"javascript","source_language":"en","source_url":"https://github.com/qmhc/vite-plugin-dts","tags":["javascript","vite","vite-plugin","ts","dts","typescript","vue","tsc","vue-tsc"],"install":[{"cmd":"npm install vite-plugin-dts","lang":"bash","label":"npm"},{"cmd":"yarn add vite-plugin-dts","lang":"bash","label":"yarn"},{"cmd":"pnpm add vite-plugin-dts","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"peer dependency - the plugin works as a Vite plugin","package":"vite","optional":false},{"reason":"peer dependency - required for type generation","package":"typescript","optional":false}],"imports":[{"note":"Default export; ESM-only. CommonJS require() will fail in some environments.","wrong":"const dts = require('vite-plugin-dts')","symbol":"vite-plugin-dts","correct":"import dts from 'vite-plugin-dts'"},{"note":"The default export is the plugin function. Named exports include types only.","wrong":"import { vitePluginDts } from 'vite-plugin-dts'","symbol":"vitePluginDts","correct":"import dts from 'vite-plugin-dts'"},{"note":"PluginOptions is a type, use import type for correctness.","wrong":"import { PluginOptions } from 'vite-plugin-dts'","symbol":"PluginOptions","correct":"import type { PluginOptions } from 'vite-plugin-dts'"}],"quickstart":{"code":"import dts from 'vite-plugin-dts'\nimport { defineConfig } from 'vite'\n\nexport default defineConfig({\n  plugins: [\n    dts({\n      include: ['src/**/*.ts'],\n      outDir: 'dist',\n      // Optional: enable declaration bundling\n      // bundleTypes: true\n    })\n  ]\n})\n// Then run 'vite build' to generate .d.ts files","lang":"typescript","description":"Shows the basic configuration of vite-plugin-dts in a Vite config file. Includes include, outDir, and optional bundleTypes."},"warnings":[{"fix":"Replace 'beforeBundle' with 'afterBootstrap' in the plugin options.","message":"The 'beforeBundle' hook has been deprecated in v5.0.0-beta. Use 'afterBootstrap' instead.","severity":"deprecated","affected_versions":">=5.0.0-beta.0"},{"fix":"Switch to ESM imports: import dts from 'vite-plugin-dts'","message":"In v5.0.0, the plugin no longer supports CommonJS require() directly; it is ESM-only.","severity":"breaking","affected_versions":">=5.0.0"},{"fix":"Set 'tsconfigPath' to the correct tsconfig file path, e.g., 'tsconfig.json'.","message":"If using TypeScript path aliases, you must configure the 'tsconfigPath' option to match the resolved path.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Specify a more precise 'include' pattern, e.g., exclude 'test' or 'stories'.","message":"The plugin may generate duplicate declarations if 'include' overlaps with resolved 'tsconfig' includes.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Ensure your tsconfig has the correct 'paths' mapping and set 'tsconfigPath' option to the correct config.","cause":"The plugin cannot resolve a module path that uses aliases not defined in TypeScript paths.","error":"Error: [vite-plugin-dts] Failed to resolve module specifier './some-module'"},{"fix":"Use 'import dts from 'vite-plugin-dts'' with ESM, and ensure the package is installed and not a type-only export.","cause":"Using default import incorrectly, or the plugin version does not support the import style being used.","error":"TypeError: dts is not a function"},{"fix":"Run 'npm install -D vite-plugin-dts' and ensure tsconfig 'types' includes 'vite/client' if needed.","cause":"Package not installed or TypeScript resolution not aware of the module.","error":"Cannot find module 'vite-plugin-dts' or its corresponding type declarations."},{"fix":"Replace 'rollupTypes: true' with 'bundleTypes: true' in the plugin options.","cause":"Using an older option name from a previous version.","error":"The 'rollupTypes' option is deprecated. Use 'bundleTypes' instead."}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}