bundle-declarations-webpack-plugin

raw JSON →
6.0.0 verified Sat Apr 25 auth: no javascript

Webpack plugin that bundles TypeScript declaration files (.d.ts) into a single output file using dts-bundle-generator. Version 6.0.0 supports Webpack 5+, Node >=16, and is ESM-only since v6 (dropped CJS support). It wraps dts-bundle-generator (v9.3.1) with Webpack integration, allowing per-entry configuration, inline libraries, sorting, and banner control. Unlike similar plugins, it focuses on minimal configuration, supports multiple entry points and bundles, and exposes full dts-bundle-generator options. Release cadence is irregular, driven by dependency updates.

error Cannot find module 'bundle-declarations-webpack-plugin'. Did you mean to import "bundle-declarations-webpack-plugin"?
cause Using require() in v6 which dropped CJS support.
fix
Change to import statement or downgrade to v5.1.1.
error TypeError: BundleDeclarationsWebpackPlugin is not a constructor
cause Using default import incorrectly or missing default export.
fix
Use: import BundleDeclarationsWebpackPlugin from 'bundle-declarations-webpack-plugin'
error Error: Plugin could not find any TypeScript files in entry
cause Entry path is incorrect or file has no .ts/.tsx extension.
fix
Verify entry path and file extension; entry must point to a TypeScript file.
error Module not found: Error: Can't resolve 'dts-bundle-generator'
cause Missing peer dependency; dts-bundle-generator not installed.
fix
Run: npm install dts-bundle-generator --save-dev
error The class "BundleDeclarationsWebpackPlugin" has no public member "apply".
cause Instantiated incorrectly or not a Webpack plugin.
fix
Ensure new BundleDeclarationsWebpackPlugin() is added to the plugins array in Webpack config.
breaking v6 removed CommonJS bundle output; require() will fail.
fix Use import syntax or downgrade to v5.1.1 if CJS is required.
deprecated options.entry may be a string array (simple entry points) in older versions; v6 still supports but prefer object for consistent behavior.
fix Use object format: new BundleDeclarationsWebpackPlugin({ entry: { filePath: './src/index.ts' } }).
gotcha Plugin does not emit any declarations if entry file has no exports; results in empty .d.ts file.
fix Ensure entry files have at least one export statement.
gotcha When using multiple entry points, ordering of combined declarations may be unpredictable; use sortNodes option for stable output.
fix Set { entry: { output: { sortNodes: true } } }.
breaking v5 upgraded dts-bundle-generator from v8 to v9; some dts-bundle-generator options changed.
fix Review dts-bundle-generator v9 migration guide; options like 'preferredConfigPath' may have changed.
security Plugin depends on dts-bundle-generator which uses libraries that may have vulnerabilities; audit transitive dependencies.
fix Run 'npm audit' regularly; consider overriding vulnerable transitive deps if needed.
gotcha Windows path handling may produce empty output file if paths contain backslashes; fixed in v5.1.1.
fix Upgrade to v5.1.1 or later; use forward slashes in configuration paths.
npm install bundle-declarations-webpack-plugin
yarn add bundle-declarations-webpack-plugin
pnpm add bundle-declarations-webpack-plugin

Minimal Webpack configuration to bundle TypeScript declarations using the plugin with default options; outputs index.d.ts alongside index.js.

import BundleDeclarationsWebpackPlugin from 'bundle-declarations-webpack-plugin';
import { resolve } from 'path';
import type { Configuration } from 'webpack';

export default <Configuration>{
  entry: './src/main.ts',
  output: {
    filename: 'index.js',
    path: resolve('./dist'),
  },
  plugins: [
    new BundleDeclarationsWebpackPlugin({
      outFile: 'index.d.ts',
    }),
  ],
};