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

CommonJS plugin doesn't recognize the __esModule field in module.exports = { __esModule: true, ... } #939

Closed
sodatea opened this issue Jul 15, 2021 · 1 comment

Comments

@sodatea
Copy link
Contributor

sodatea commented Jul 15, 2021

Expected Behavior

Both imports from symbol and symbol2 return the .default field because they are both compiled from an ES module and contain the __esModule field.

Actual Behavior

The CommonJS plugin only recognizes the one with exports.__esModule. The one with module.exports = { __esModule: true, default: ... } is treated as a normal CJS module.

Additional Information

The module.exports = { __esModule: true, default: ... } pattern is found in babel-runtime v6 https://unpkg.com/browse/babel-runtime@6.26.0/core-js/symbol.js

It is used in some old codebases. So this issue causes incompatibility with them.

See also vitejs/vite#4090

githoniel added a commit to gem-mine/plugins that referenced this issue Jul 16, 2021
guybedford pushed a commit that referenced this issue Jul 24, 2021
#942)

* fix(commonjs): convert module.exports with `__esModule` property(#939)

* test(commonjs): add test sample for cjs with esm-property

* feat(commonjs): defaultIsModuleExports support module.exports

* fix(commonjs): do not check right node in module.exports reassgin when defaultIsModuleExports = false(#935)
@guybedford
Copy link
Contributor

Fixed in #942.

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