Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: BundleDeclarationsWebpackPlugin is not a constructor #31

Open
cnestor1 opened this issue Nov 13, 2024 · 2 comments
Open

TypeError: BundleDeclarationsWebpackPlugin is not a constructor #31

cnestor1 opened this issue Nov 13, 2024 · 2 comments

Comments

@cnestor1
Copy link

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
Copy link

SzczeklikJakub commented Nov 21, 2024

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({
	//...
})

@mark-bailey-axomic
Copy link

mark-bailey-axomic commented Nov 29, 2024

I solved this by declaring the import like this:

const { BundleDeclarationsWebpackPlugin } = require("bundle-declarations-webpack-plugin");

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants