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
The esmodules target should be more future friendly #8809
Comments
Hey @philipwalton! We really appreciate you taking the time to report an issue. The collaborators If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack |
I'm not certain I see the difference between these two cases since the lower bar determines the transpilation required afaik.
should be treated equivalently to
Am I missing something? |
There's a subtle difference between the two. In the former you're including Chrome 60-67 (since current Chrome is 69), and in the latter you're only including Chrome 68-69 (speaking specifically about Chrome). And my point above was, in two years when the current Chrome version is 86 the former will include Chrome versions 60-84, and the latter will only include Chrome 85-86. As more and more JS features get added to the language and get implemented in modern browsers, the need to care about Chrome 60 will go away, but the need to support IE11 will likely still be real. That's why I say the |
It's an interesting idea, but it does break one specific part of the pattern. Let's use the Chrome 86 example: Let's pretend Chrome 85 adds a feature, and our configuration here means the feature is not transpiled by Babel ( Progressive transpilation is likely a better long term answer. With clear input signals from the However, I'd love to hear others thoughts as well, perhaps compatibility isn't as strong of a reason to continue with the model as I believe it is. |
I mean, from my perspective the whole point of browserlist (and tools that use it like autoprefixer and babel-preset-env), is that you can specify a relative query and the required transforms/polyfills/vendor prefixes/etc. needed will slowly change over time.
It may break the new That default is pretty inclusive, so if you exclude from that list any browsers that don't support modules, I think it'd be a fairly safe way to deploy ES module scripts. |
The default configuration has a likely lowest common denominator of IE11 (https://browserl.ist/?q=%3E+0.5%25%2C+last+2+versions%2C+Firefox+ESR%2C+not+dead). This is a pretty inclusive list, and is well served by the default With the aforementioned recommendation, incompatibility is completely under the developer's control (I think that's really nice). But it's more likely to create scenarios where browsers are unsupported entirely. A tradeoff that is worth a bit of consideration. Edit: This kind of incompatibility is why progressive transpilation is an interesting longer term solution for those willing to add a bit more complexity. And, hopefully, with clearer signals from browsers regarding supported features. Double edit: Terms and language clarifications. |
Interestingly, the fix for #9465 now means that |
Regenerator inclusion seems like a good baromwter for whether this is going the right direction. I'm wondering if it's worth making a differentiation here between "widespread support" and "free from all browser bugs"? |
Actually we have a test that ensures that generators aren't transpiled: https://github.com/babel/babel/tree/master/packages/babel-preset-env/test/fixtures/preset-options/esmodules-async-functions |
@nicolo-ribaudo Here's a codesandbox showing generator functions being added to a very simple source file when https://codesandbox.io/embed/goofy-frost-1ened On further examination, you're correct that regenerator isn't being included, but the transformation of async functions is still pretty heavy (and something we'd expect to be natively-supported in "modern" environments, which is what |
Can https://github.com/babel/preset-modules solve this? |
Speaking as someone from the future you envisioned, the This made me look into the possibility of using my current browserslist query with the addition of That's not how the |
Wdyt about adding |
@nicolo-ribaudo, that would certainly solve the problem! I'm not sure if the current default behavior is useful (?), so perhaps the "intersects" option could eventually become the default. |
I have moved to discussion to babel/rfcs#2 (comment), since we are working on moving the |
Fixed by #12189. It will be released in the next minor version as part of the new top-level |
Feature Request
I'm super glad to see the
esmodules
alias directly supported inpreset-env
, but I have concerns that it will very soon become mostly useless.While it's true that today most module-supporting browsers are generally modern, that won't be true a few years from now. For example, when Chrome 86 ships in two years, Chrome 61 will seem horribly old, but people using the
esmodules
target will still be getting transpilations and polyfills applied for it.Today the
esmodules
target is kind of like a whitelist for any browsers greater than or equal to the minimum module-supporting browsers versions specified here. But it'd actually be much better as a blacklist that filters out any browsers that don't support modules.To understand the difference, consider what I currently do on my blog:
I'd like to see the
esmodule
target work similarly. For example, I'd like to be able to do something like this:And that would effectively turn my query into this:
This would allow me to specify my feature support exactly as I'm used to, but I'd be sure I wasn't getting any features not needed by browsers that work with
<script type="module">
./cc @kristoferbaxter
The text was updated successfully, but these errors were encountered: