{"id":15878,"library":"types-webpack-bundler","title":"Webpack TypeScript Declaration Bundler","description":"types-webpack-bundler is a specialized webpack plugin designed to combine multiple TypeScript declaration files (`.d.ts`) generated by `ts-loader` (or similar tools) into a single, consolidated declaration file. Unlike standard declaration bundling which often produces external modules, this plugin recomposes declarations to mimic an 'internal module' structure, exposing classes and interfaces to a global-like module space. This is a fork of an unmaintained original library, updated to support Webpack 5. Its primary use case is highly niche: allowing external modules to behave like internal modules for specific scenarios, such as mapping prefixed URIs to module paths. The current stable version is 1.0.2. It does not have a stated regular release cadence and is described as an 'experimental setup' by its author, suggesting infrequent updates unless a specific need arises.","status":"maintenance","version":"1.0.2","language":"javascript","source_language":"en","source_url":"git@github.com:droyson/types-webpack-bundler","tags":["javascript"],"install":[{"cmd":"npm install types-webpack-bundler","lang":"bash","label":"npm"},{"cmd":"yarn add types-webpack-bundler","lang":"bash","label":"yarn"},{"cmd":"pnpm add types-webpack-bundler","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Required as a peer dependency for webpack plugin integration.","package":"webpack","optional":false}],"imports":[{"note":"While the README shows `require('types-webpack-bundler')`, the package exports a default for ESM compatibility. For TypeScript, direct import is preferred.","wrong":"const DeclarationBundlerPlugin = require('types-webpack-bundler').default;","symbol":"DeclarationBundlerPlugin","correct":"import DeclarationBundlerPlugin from 'types-webpack-bundler';"},{"note":"This is the CommonJS `require` syntax explicitly shown in the webpack.config.js example for Node.js environments.","symbol":"DeclarationBundlerPlugin","correct":"const DeclarationBundlerPlugin = require('types-webpack-bundler');"}],"quickstart":{"code":"import * as path from 'path';\nimport DeclarationBundlerPlugin from 'types-webpack-bundler';\n\nexport default {\n    entry: './src/init.ts',\n    output: {\n        filename: './builds/bundle.js',\n        path: path.resolve(__dirname, 'dist')\n    },\n    resolve: {\n        extensions: ['.ts', '.tsx', '.js']\n    },\n    module: {\n        rules: [\n            {\n                test: /\\.ts(x?)$/,\n                loader: 'ts-loader',\n                options: {\n                    compilerOptions: { declaration: true, outDir: './builds' } // ts-loader must generate declarations\n                }\n            }\n        ]\n    },\n    plugins: [\n        new DeclarationBundlerPlugin({\n            moduleName:'some.path.moduleName',\n            out:'./builds/bundle.d.ts',\n            excludedReferences: []\n        })\n    ],\n    mode: 'development' // or 'production'\n};","lang":"typescript","description":"This configuration demonstrates how to integrate `types-webpack-bundler` into a webpack setup with `ts-loader` to generate a bundled declaration file. It shows the plugin options `moduleName` and `out` in action."},"warnings":[{"fix":"Evaluate if your project truly requires this niche functionality. In most cases, standard `tsc` declaration generation and bundling tools (like `rollup-plugin-dts` or `webpack`'s built-in capabilities for modules) are more appropriate and less 'experimental'.","message":"This library is explicitly described as an 'experimental setup' and is intended for a very specific and rare use case. It allows external modules to mimic internal modules by re-composing declaration files into a global-like scope. For most TypeScript projects using modern module systems (ESM or CommonJS), this approach is generally not recommended or necessary.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Ensure your TypeScript configuration (`tsconfig.json`) includes `\"declaration\": true` and your `ts-loader` (or equivalent) setup is configured to process and emit declaration files. Verify that individual `.d.ts` files are being generated in your build output before the bundler runs.","message":"The plugin expects separate declaration files to be generated by a loader (e.g., `ts-loader` with `declaration: true` in `tsconfig.json`). If the loader is not configured to emit these files, the bundler will have no input and will likely fail or produce an empty output.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Keep an eye on the project's GitHub repository for updates if you plan to upgrade Webpack beyond v5. Be prepared for potential compatibility issues with future Webpack releases or consider migrating to a more actively maintained declaration bundling solution if your use case evolves.","message":"This is a fork of an unmaintained original library. While it supports Webpack 5, it implies that future Webpack major versions might not be immediately supported without further updates to this project.","severity":"breaking","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-21T00:00:00.000Z","next_check":"2026-07-20T00:00:00.000Z","problems":[{"fix":"Ensure you are using Webpack 5 as a peer dependency. Double-check your `webpack.config.js` to confirm the plugin is instantiated correctly: `new DeclarationBundlerPlugin({...})` within the `plugins` array.","cause":"The plugin is likely being initialized incorrectly or in an incompatible Webpack version/environment where the expected Webpack plugin API shape is not present.","error":"TypeError: Cannot read properties of undefined (reading 'compilation')"},{"fix":"Ensure the directory specified in the `out` option (e.g., `./builds/`) exists before webpack runs, or configure webpack's output path to ensure it creates necessary directories. You might need to use a tool like `fs.mkdirSync` in a pre-build script or rely on webpack's output directory creation.","cause":"The output directory specified for the bundled declaration file (`out` option) does not exist, and the plugin might not automatically create it.","error":"Error: ENOENT: no such file or directory, open '.../bundle.d.ts'"}],"ecosystem":"npm"}