You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Bug]: babel/preset-env - document says esmodules is intersected, build warning says its ignored. #15371
Hey @epreston! We really appreciate you taking the time to report an issue. The collaborators on this project attempt to help as many people as possible, but we're a limited number of volunteers, so it's possible this won't be addressed swiftly.
If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack community that typically always has someone willing to help. You can sign-up here for an invite.
However, for backward compatibility we couldn't change the pre-existing behavior of @babel/preset-env's targets option, so esmodules there completely overwrites browsers. We need to document this.
I recommend using the top-level targets option, instead of @babel/preset-env's targets, because:
it has the better intersection behavior
can also be read by other plugins that can adjust their behavior based on your targets, while if you use it just in @babel/preset-env other plugins will always assume the oldest possible targets.
esmodules now has a "intersect" value, and it works as documented (debug shows that esmodules and browsers are intersected):
presets: [
[
'@babel/preset-env',
{
loose: false,
shippedProposals: true,
bugfixes: true,
modules: false,
debug: true,
targets: {
esmodules: 'intersect',
browsers: 'defaults and not dead, last 5 years',
},
},
],
but you still get a warning stating that it's ignored, while that is not true:
@babel/preset-env: esmodules and browsers targets have been specified together.
`browsers` target, `defaults and not dead, last 5 years` will be ignored.
Activity
babel-bot commentedon Jan 26, 2023
Hey @epreston! We really appreciate you taking the time to report an issue. The collaborators on this project attempt to help as many people as possible, but we're a limited number of volunteers, so it's possible this won't be addressed swiftly.
If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack community that typically always has someone willing to help. You can sign-up here for an invite.
epreston commentedon Jan 26, 2023
Thank you babel-bot. We need to update the documentation or tool.
nicolo-ribaudo commentedon Jan 26, 2023
It should definitely be intersected, I'll check what the code does.
nicolo-ribaudo commentedon Jan 26, 2023
If you specify your targets at the top level of your config (so in the generic Babel options — https://babeljs.io/docs/en/options#targetsesmodules),
esmoduleswill be intersected withbrowsers:However, for backward compatibility we couldn't change the pre-existing behavior of
@babel/preset-env'stargetsoption, soesmodulesthere completely overwritesbrowsers. We need to document this.I recommend using the top-level
targetsoption, instead of@babel/preset-env'stargets, because:@babel/preset-envother plugins will always assume the oldest possible targets.liuxingbaoyu commentedon Jan 26, 2023
We can also modify the message in code to link to the documentation.
epreston commentedon Jan 26, 2023
I see, that makes sense. You are right, using the top-level targets option is the best way to go.
Should I leave this open to capture the "documentation" task ?
Update .babelrc.json
nicolo-ribaudo commentedon Jan 26, 2023
Yes please! (or, if you want to open a PR to github.com/babel/website, that would be even better 👀)
epreston commentedon Jan 27, 2023
Good idea, I will try my hand at updating the documentation. I'll reference the info you provided here and close issue once the PR is submitted.
epreston commentedon Jan 27, 2023
PR Submitted. Thank you for clarifying this for me.
epreston commentedon Mar 3, 2023
I did that, waited a month. What's the process ?
nicolo-ribaudo commentedon Mar 4, 2023
Sorry, the only problem was that I somehow forgot about your PR 😅
epreston commentedon Mar 4, 2023
Maybe it's for the best. @JLHwung was able to help us refine it with the extra time.
babel: move to toplevel target
lazka commentedon Aug 4, 2025
The situation is more confusing now.
esmodulesnow has a "intersect" value, and it works as documented (debug shows that esmodules and browsers are intersected):but you still get a warning stating that it's ignored, while that is not true:
Ideally the warning would not be shown there.
JLHwung commentedon Aug 5, 2025
@lazka Yes, you are right. We overlooked the fact that
esmodulescan beintersectas well:babel/packages/babel-preset-env/src/index.ts
Lines 277 to 282 in 5051613
Do you want to open a PR?