dominicbirch / bundle-declarations-webpack-plugin

Webpack wrapper around dts-bundle
MIT License
8 stars 1 forks source link

TypeError: BundleDeclarationsWebpackPlugin is not a constructor #31

Open cnestor1 opened 1 week ago

cnestor1 commented 1 week ago

I am getting this error when merging typescript files using the Webpack BundleDeclarationsWebpackPlugin.

TypeError: BundleDeclarationsWebpackPlugin is not a constructor

What's wrong with my configuration below?

My Webpack config is:

const path = require('path');
const nodeExternals = require('webpack-node-externals');
const BundleDeclarationsWebpackPlugin = require("bundle-declarations-webpack-plugin");

module.exports = {
  entry: './src/index.ts',
  mode: 'production',
  output: {
   ...
  },
  devtool: 'source-map',
  module: {
      ...
  },
  plugins: [
    new BundleDeclarationsWebpackPlugin({
      entry: './dist/types/index.d.ts',    //specify the entry point for your declaration file (defaults to 'index.d.ts')
      outFile: './dist/index.d.ts',        //specify the output file name (defaults to 'index.d.ts')
    }),
  ],
  resolve: {
    extensions: ['.tsx', '.ts', '.js']
  }
};

package.json:

"devDependencies": {
    "@babel/cli": "^7.25.9",
    "@babel/core": "^7.26.0",
    "@babel/preset-env": "^7.26.0",
    "@babel/preset-react": "^7.25.9",
    "@babel/preset-typescript": "^7.26.0",
    "@rollup/plugin-commonjs": "28.0.1",
    "@rollup/plugin-node-resolve": "15.3.0",
    "@types/node": "^22.9.0",
    "@types/react": "^18.3.12",
    "@types/react-dom": "^18.3.1",
    "@types/webpack": "^5.28.5",
    "@types/webpack-dev-server": "^4.7.2",
    "@types/webpack-node-externals": "^3.0.4",
    "babel-loader": "^9.2.1",
    "bundle-declarations-webpack-plugin":"5.1.1",
    "css-loader": "^7.1.2",
    "html-webpack-plugin": "5.6.3",
    "sass-loader": "16.0.3",
    "style-loader": "^4.0.0",
    "ts-loader": "^9.5.1",
    "ts-node": "^10.9.2",
    "typescript": "^5.6.3",
    "webpack": "^5.96.1",
    "webpack-cli": "^5.1.4",
    "webpack-dev-server": "5.1.0",
    "webpack-node-externals": "3.0.0"
  },

tsconfig.json

{
  "compilerOptions": {
    "target": "es2016", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
    "jsx": "react-jsx", /* Specify what JSX code is generated. */
    "module": "ESNext", /* Specify what module code is generated. */
    "moduleResolution": "bundler", /* Specify how TypeScript looks up a file from a given module specifier. */
    "resolveJsonModule": true, /* Enable importing .json files. */
    "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */
    "sourceMap": true, /* Create source map files for emitted JavaScript files. */
    "outDir": "dist/types", /* Specify an output folder for all emitted files. */
    "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 
     allowSyntheticDefaultImports' for type compatibility. */
    "forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */
    "strict": true, /* Enable all strict type-checking options. */
    "skipLibCheck": true /* Skip type checking all .d.ts files. */
  },
  "include": [
    "src/**/*"
  ],
  "exclude": [
    "node_modules",
    "dist"
  ] // Exclude `node_modules` and the output directory
}
SzczeklikJakub commented 3 days ago

BundleDeclarationsWebpackPlugin is not a class. You should create a new object with default values ​​by::

new BundleDeclarationsWebpackPlugin.default;

or with your settings:

new BundleDeclarationsWebpackPlugin.default({
    //...
})