npm-dts-webpack-plugin
raw JSON → 1.3.13 verified Sat Apr 25 auth: no javascript maintenance
Webpack plugin (v1.3.13) that generates a single bundled index.d.ts file for an NPM package, enabling code intelligence in consumers without shipping TypeScript sources. It wraps the npm-dts library and runs the TypeScript compiler declaratively. Releases are infrequent (last update 2021) and the plugin is in maintenance mode. Key differentiator: simple integration into Webpack pipelines as a plugin rather than a separate CLI step.
Common errors
error TypeError: Cannot read property 'options' of undefined ↓
cause Webpack configuration lacks a valid 'plugins' array or plugin is not instantiated correctly.
fix
Ensure plugins: [new NpmDtsPlugin()] is placed inside module.exports.
error Error: Could not find tsconfig.json ↓
cause Plugin needs a tsconfig.json in the project root or root option pointing to correct directory.
fix
Create tsconfig.json or set root option: new NpmDtsPlugin({ root: __dirname })
error error TS6053: File 'index.ts' not found ↓
cause Entry file (default index.ts) is missing or entry option points to wrong path.
fix
Specify entry: new NpmDtsPlugin({ entry: 'src/main.ts' })
Warnings
breaking Plugin requires Node.js >=10 and Webpack 4/5. Webpack 2/3 are not supported. ↓
fix Update to Webpack 4 or 5 and Node >=10.
breaking The plugin may fail if TypeScript rootDir is not correctly inferred; define rootDir in tsconfig.json to avoid issues. ↓
fix Set rootDir explicitly in tsconfig.json under compilerOptions.
deprecated The force option is deprecated; non-critical errors should be fixed instead of ignored. ↓
fix Remove force: true and address TypeScript errors in source.
breaking Plugin generates index.d.ts only; if multiple entry points exist, behavior is undefined. ↓
fix Use a single entry point or consider alternative dts generation tools.
Install
npm install npm-dts-webpack-plugin yarn add npm-dts-webpack-plugin pnpm add npm-dts-webpack-plugin Imports
- NpmDtsPlugin wrong
import NpmDtsPlugin from 'npm-dts-webpack-plugin';correctconst NpmDtsPlugin = require('npm-dts-webpack-plugin'); - NpmDtsPlugin (ESM)
import NpmDtsPlugin from 'npm-dts-webpack-plugin'; - Options
import type { Options } from 'npm-dts-webpack-plugin';
Quickstart
const NpmDtsPlugin = require('npm-dts-webpack-plugin');
module.exports = {
entry: './src/index.ts',
output: { filename: 'bundle.js', path: __dirname + '/dist' },
resolve: { extensions: ['.ts', '.js'] },
module: { rules: [{ test: /\.ts$/, use: 'ts-loader', exclude: /node_modules/ }] },
plugins: [new NpmDtsPlugin({
logLevel: 'info',
output: 'index.d.ts'
})]
};