-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Runtime support for __esModule
annotations
#3393
Conversation
❌ @Jarred-Sumner 9 files with test failures on bun-darwin-aarch64:
|
❌ @Jarred-Sumner 6 files with test failures on linux-x64:
|
❌ @Jarred-Sumner 6 files with test failures on linux-x64-baseline:
|
❌ @Jarred-Sumner 8 files with test failures on bun-darwin-x64-baseline:
|
Note that "other tooling" here also includes Node.js itself. If you really thing the ecosystem should move in this direction, can we at least propose a new flag to Node.js |
Or at least figure out how to distinguish Node.js usage from browser style interop? |
It doesn’t diverge by default, Node.js-like is what this keeps unless the CommonJS module has __esModule exported. The other difference is __esModule is excluded from the ESM namespace export (we could skip doing that though) Where I feel the least good about this PR is not paying attention to .mjs or I think supporting __esModule overall will make more packages work the way people expect. |
f1f4a3d
to
bbb2e38
Compare
I have updated it to respect |
Completely understood supporting current bundler behaviours is needed, this sounds like it might be the right kind of compromise as Webpack worked out. |
This interprets the
__esModule
annotation at runtime:default
and the__esModule
property is defined onmodule.exports
, then thedefault
ESM exportbecomes the value of
module.exports.default
(like Babel), unless the enclosing package.json's"type"
field is set to"module"
(like esbuild)__esModule
annotation is not defined onmodule.exports
, then weset the
default
ESM export tomodule.exports
or if"package.json"'s
"type"field is set to
"module"` (like Node.js)Note that this interpretation is slightly different than esbuild and other tooling:
__esModule
annotation. We only look for the existence of the__esModule
property onmodule.exports
. This is for performance reasons (bun loops through themodule.exports
objects at runtime).Relevant links:
Fixes #3383
cc @andrewbranch @colinhacks @paperdave