{"id":15863,"library":"ts-declaration-webpack-plugin","title":"TypeScript Declaration Webpack Plugin","description":"This Webpack plugin streamlines the generation of TypeScript declaration files (`.d.ts`) by producing a single, bundled declaration file for each entry point configured in Webpack. It targets `ts` and `tsx` files by default and automatically places the generated `.d.ts` files alongside their corresponding compiled JavaScript outputs. The current stable version is 1.2.3. As a Webpack plugin, its release cycle is typically driven by maintenance, bug fixes, or compatibility updates with new Webpack or TypeScript versions rather than a fixed schedule. Its primary differentiator is simplifying the output of declaration files for complex projects with multiple Webpack entry points, contrasting with manual `tsc` commands or more complex bundlers.","status":"active","version":"1.2.3","language":"javascript","source_language":"en","source_url":"https://github.com/unimonkiez/ts-declaration-webpack-plugin","tags":["javascript","dts","defenition-files","typscript","webpack","bundler"],"install":[{"cmd":"npm install ts-declaration-webpack-plugin","lang":"bash","label":"npm"},{"cmd":"yarn add ts-declaration-webpack-plugin","lang":"bash","label":"yarn"},{"cmd":"pnpm add ts-declaration-webpack-plugin","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Required peer dependency for webpack integration.","package":"webpack","optional":false}],"imports":[{"note":"As of v1.x, the plugin's main export is designed for CommonJS environments. Using ES module `import` syntax directly for the main class may lead to runtime errors.","wrong":"import TsDeclarationWebpackPlugin from 'ts-declaration-webpack-plugin';","symbol":"TsDeclarationWebpackPlugin","correct":"const TsDeclarationWebpackPlugin = require('ts-declaration-webpack-plugin');"}],"quickstart":{"code":"const path = require('path');\nconst TsDeclarationWebpackPlugin = require('ts-declaration-webpack-plugin');\n\nmodule.exports = {\n    mode: 'production',\n    entry: {\n        app: './src/main.ts',\n        component: './src/component.tsx',\n    },\n    output: {\n        path: path.resolve(__dirname, 'dist'),\n        filename: '[name].js',\n        libraryTarget: 'umd'\n    },\n    module: {\n        rules: [\n            {\n                test: /\\.tsx?$/,\n                use: 'ts-loader',\n                exclude: /node_modules/,\n            },\n        ],\n    },\n    resolve: {\n        extensions: ['.tsx', '.ts', '.js'],\n    },\n    plugins: [\n        new TsDeclarationWebpackPlugin({\n            name: '[name].d.ts', // Optional: customize declaration file name\n            test: /\\.(ts|tsx)$/, // Optional: customize file types to process\n        }),\n    ]\n};\n","lang":"javascript","description":"This Webpack configuration demonstrates how to integrate `ts-declaration-webpack-plugin` to generate bundled `.d.ts` files for 'app' and 'component' entries, alongside their compiled JavaScript."},"warnings":[{"fix":"Ensure your project uses Webpack 4.x. For Webpack 5+, consider alternative declaration bundling solutions or check for a newer major version of this plugin (if available) that explicitly supports Webpack 5+.","message":"The plugin is explicitly designed for Webpack 4, specifying `webpack: \"^4.0.0\"` as a peer dependency. Using it with Webpack 5 or newer versions will likely lead to build failures or unexpected behavior due to significant API changes in Webpack's plugin system.","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"Configure the `test` option when instantiating the plugin: `new TsDeclarationWebpackPlugin({ test: /\\.(ts|tsx|mts|cts)$/ })` to match all desired file types.","message":"By default, the plugin only processes files matching `test: /\\.(ts|tsx)$/`. If your project uses other TypeScript-related extensions (e.g., `.mts`, `.cts`, or custom extensions), you must explicitly configure the `test` option in the plugin's constructor to include these extensions, otherwise, declarations will not be generated for them.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"If granular declaration files are required, consider using `tsc --emitDeclarationOnly` directly or explore other tools/plugins that specifically support multi-file declaration output per entry point.","message":"This plugin is designed to output a *single* bundled `.d.ts` file per Webpack entry point. It does not provide options for generating multiple, separate declaration files for individual modules within a single entry, which might be desired for more granular package distribution or specific library module structures.","severity":"gotcha","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":"Run `npm install webpack@^4.0.0` or `yarn add webpack@^4.0.0` to install the compatible Webpack version.","cause":"Webpack is a peer dependency and must be installed separately in your project.","error":"ModuleNotFoundError: Module not found: Error: Can't resolve 'webpack' in '...'"},{"fix":"Ensure you are using `const TsDeclarationWebpackPlugin = require('ts-declaration-webpack-plugin');` in your Webpack configuration file.","cause":"This usually indicates an incorrect import or require statement, such as using ES module `import` syntax in a CommonJS context, or attempting to destructure a non-object export.","error":"TypeError: TsDeclarationWebpackPlugin is not a constructor"},{"fix":"Update the `test` option in the plugin configuration to include your specific file extensions: `new TsDeclarationWebpackPlugin({ test: /\\.(ts|tsx|mts|cts)$/ })`.","cause":"The plugin's default `test` option only matches `.ts` and `.tsx` files, excluding newer or custom TypeScript extensions.","error":"Declaration files not generated for some TypeScript files (e.g., .mts, .cts)."},{"fix":"Downgrade your Webpack version to 4.x (`npm install webpack@^4.0.0`) or seek an alternative plugin that explicitly supports Webpack 5 and beyond.","cause":"The plugin is only compatible with Webpack 4, and its internal APIs are not compatible with Webpack 5+.","error":"Webpack compilation fails with errors related to plugin API (e.g., 'hooks' property missing or undefined) when using Webpack 5."}],"ecosystem":"npm"}