codepunkt/webpack-license-plugin

Upgrade from 4.2.2 to 4.2.3 / 4.3.0 => TypeError: WebpackLicensePlugin is not a constructor

Closed this issue · 5 comments

Hi,

I use WebpackLicensePlugin on my project for a few years. Today I simply upgraded the webpack-license-plugin in my package.json (from 4.2.2 to 4.3.0) and I systematically get an error when running webpack : TypeError: WebpackLicensePlugin is not a constructor.

Note : I also tried 4.2.3 and I got the same result.

To isolate the problem, I've emptied my webpack configuration file so that it only contains the following code (not a valid webpack configuration file, but it's not a problem as we only want to isolate and reproduce the raising error) :

const WebpackLicensePlugin = require('webpack-license-plugin');
console.error('** Before new WebpackLicensePlugin');
const plugin = new WebpackLicensePlugin();
console.error('** After new WebpackLicensePlugin');

The result :

Running webpack (webpack.prod.js)...
** Before new WebpackLicensePlugin
[webpack-cli] Failed to load '[hidden]/webpack.prod.js' config
[webpack-cli] TypeError: WebpackLicensePlugin is not a constructor
    at Object.<anonymous> ([hidden]/webpack.prod.js:3:16)
    at Module._compile (node:internal/modules/cjs/loader:1159:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1213:10)
    at Module.load (node:internal/modules/cjs/loader:1037:32)
    at Module._load (node:internal/modules/cjs/loader:878:12)
    at Module.require (node:internal/modules/cjs/loader:1061:19)
    at require (node:internal/modules/cjs/helpers:103:18)
    at WebpackCLI.tryRequireThenImport ([hidden]/node_modules/webpack-cli/lib/webpack-cli.js:223:30)
    at loadConfigByPath ([hidden]/node_modules/webpack-cli/lib/webpack-cli.js:1406:38)
    at [hidden]/node_modules/webpack-cli/lib/webpack-cli.js:1460:88
error Command failed with exit code 2.

I use webpack 5 :

    "webpack": "^5.88.2",
    "webpack-cli": "^5.1.4",
    "webpack-dev-server": "^4.15.1",
    "webpack-license-plugin": "^4.2.3",

I understand that I probably make a very basic mistake, but I must admit that I don't understand what (I checked the documentation and the installation section does not seem to have changed since 4.2.2).

Thank you in advance for your return.

@jbrazeau thanks for reporting! I’m currently on a business trip, but will look into it once I’m back!

Feel free to tell me if I can help to investigate, and more generally thank you for webpack-license-plugin which is very useful for us 😉.

cmlenz commented

FWIW, same here when upgrading from 4.2.2 to 4.3.0.

@codepunkt

Changing
const WebpackLicensePlugin = require('webpack-license-plugin')
to
const WebpackLicensePlugin = require('webpack-license-plugin').default
works for us.

Maybe this info helps to identify and fix the problem.

Thanks for the reports, @bitschubse, @cmlenz and @jbrazeau!

Wasn't the easiest thing to fix after quite a lot of under the hood changes leading up to the previous releases.
The version with the fix is 4.4.2. Enjoy!