What is the current behavior?
Many modules published to npm are using “auto” exports (https://rollupjs.org/guide/en#output-exports-exports, but there is also a popular babel plugin which adds this behaviour https://github.com/59naga/babel-plugin-add-module-exports#readme) which is supposed to ease interop with node (removing “pesky”
.default for CJS consumers when there is only a default export in the module).
And with that depending on a package authored solely in CJS (which still is really common) which depends on a package authored using the mentioned “auto” mode is dangerous and broken.
Why? Because webpack is using the “module” entry from package.json (thus using real default export) without checking the requester module type (which is cjs here). CJS requester did not use a
.default when requiring the package with auto mode, because from its perspective there was no such thing.
If the current behavior is a bug, please provide the steps to reproduce.
https://github.com/Andarist/webpack-module-entry-from-cjs-issue . Exported value should be
"foobar42" instead of
What is the expected behavior?
Webpack should deopt (ignoring .mjs & “module”) its requiring behaviour based on the requester type.
Other relevant information:
webpack version: latest
Node.js version: irrelevant
Operating System: irrelevant
Additional tools: irrelevant