Skip to content

ESM build does not work in ES module config files #994

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

Closed
mrxz opened this issue Mar 12, 2024 · 1 comment
Closed

ESM build does not work in ES module config files #994

mrxz opened this issue Mar 12, 2024 · 1 comment

Comments

@mrxz
Copy link
Contributor

mrxz commented Mar 12, 2024

I tried using the published ESM build in a Webpack project, but encountered errors directly upon importing the plugin using:

import LicensePlugin from 'webpack-license-plugin';

The error in question:

SyntaxError: Named export 'WebpackError' not found. The requested module 'webpack' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:

Digging some more into it, there seems to be two issues with the current ESM bundle preventing it from being used in an ES Module webpack config file:

  1. There are named imports from CommonJS modules, which aren't always supported by Node as the error message also indicates. TypeScript allows this just fine, hence it not causing issues when building. See Tracking issue: Named imports from CJS module incorrectly allowed in nodenext microsoft/TypeScript#54018
  2. The bundle contains a CommonJS specific footer (added here), which isn't valid in an ES module.
@codepunkt
Copy link
Owner

Thanks @mrxz!

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

2 participants