-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
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
[@babel/preset-env] useBuiltIns for libraries? #7267
Comments
Hey @julien-f! 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 |
For what its worth - I will work soon-ish on implementing support for custom polyfills in preset-env ( |
Duplicates #6629 and relates also to #6628. This is feature is desperately needed, and is a low hanging fruit. It is the final missing piece of the preset-env puzzle. @hzoo I really wish Babel would prioritise features for package authors rather than package consumers, because the positive effects ripple throughout the community on a massive scale. People who use packages to complete commercial projects are paid to solve their problems one way or another, but even a little bit of friction caused by tools really distracts and demotivates people working for free to produce open source packages that benefit everyone. It's sad this issue hasn't been triarged with tags or anything since it was raised over 2 months ago in January. Many packages have ~ 1kb source yet ~20kb of polyfills added by babel because authors are stuck between choosing:
|
I definitely agree that it would be great to have this too. Regarding transform-runtime specifically, it doesn't work with any instance methods. So anything like Yes, I made those issues because I had wanted to tackle them but I had personal stuff to deal with (and still dealing with) and there are other priorities as well like releasing v7 among other things.
I'm confused by this. I don't think it's that productive to just point out that the work isn't done and is easy. I feel like there's an issue with your statement - isn't what you are saying the same thing that would equally demotivate someone to work on this issue as well? Are you saying that because we aren't focusing on this issue that is demotivates you and others from doing open source? If this is something you really want to happen you can also help with this effort as well. I don't think it's easy, but if it is then we are open to you or someone else making a pull request too, or getting help/feedback on it in Slack as well. I'd like to think we don't just use GitHub as a place to ask for feature requests only the maintainers will do, but that people will get involved and actually do the work they want to see happen. There are actually other things that are important, and not a lot of people working on this project (although it does feel like people forget that). Even if everyone was full time it wouldn't be enough, let alone now. |
Libraries bringing in their own polyfills, even if self-contained library-like ones, is actually a problem for final users / packagers because, if they do polyfill their environment, they now have the library redundantly trying to use their library-isolated polyfill while the global environment is already polyfilled. I don't think there's any "right answer" here; I lean on the side of having final users provide all polyfills, and libraries should document which ones they need. Once we get preset-env safe for use in (most of) node_modules, I believe we'll be closer to that ideal. |
I'm aware, and don't use instance methods. It is be a good addition to the pros/cons list though.
Yes. It is fair to say learning best practices and what is or isn’t possible regarding transpilation and polyfilling cost several weeks over 2 years, making frustrating or embarrassing mistakes along the way. At the moment, I don't feel confident promoting my latest package until the polyfill situation is under control.
Triaging issues for maximum impact is productive. I don't mean that working on the feature is easy per se, but that it is comparatively easy compared to the volume and complexity of other things being worked on.
My intention is not to demotivate anyone, but rather to motivate package authors to support each other as a priority. The barriers to entry to writing best practice packages are prohibitively high. We should not have to choose certain best practices sacrificing others.
I feel you and appreciate your efforts ❤️. I only share this so you don’t think of me as a parasite… But I quit my job a year and a half ago to immerse in open-source and have spent many months working unpaid, full time (spending tens of thousands of dollars of personal savings) on projects such as the GraphQL multipart request spec, apollo-upload-client/apollo-upload-server and recently graphql-react. I contribute PRs to several projects; I just have nothing left to give to solve this particular issue. If I could clone myself and learn enough about the inner workings of Babel to do it I would! |
According to babel/babel#7267 it seems that library authors probably don't want to include polyfills. After a bunch of problems with babel and core-js and the now familiar `Module not found: Error: Can't resolve 'core-js/modules/es7.string.pad-end'` error I'm inclined to agree. Polyfills need to be the concern of the consuming application.
@rtsao I'm wondering where we're at with this issue, or if anyone could give me some guidance on setting up a babel configuration to solve a very unique problem. I've asked stack-overflow and the slack community already. TLDR: I'm building a library as a node_module. Shared node_module dependencies between my library (imported as a node_module) and my main "parent" application that requires it - can collide and cause issues. How can i create a babel config in the library to avoid polluting the global namespace? Longer description: Problem: When I import my node_module (that The stack overflow post with more specific code examples is here: https://stackoverflow.com/questions/52507114/how-do-i-compile-code-for-a-web3-js-related-sdk-so-it-doesnt-interfere-with-the I've experimented with many babel presets, and I'm not sure if there is one plugin that is causing this issue, or if it's even possible to create a dependency graph in a node_module without touching the global namespace. @julien-f I saw you said that the
Yet I still get the same issue. Do I have to do something with corejs? |
any progress? |
|
I agree, let's close this for now 🙂 |
Is this a bug report or feature request?
More a discussion which may leads to a feature request in
@babel/preset-env
.Summary
The
useBuiltIns
features is great but its usage may not be appropriate for libraries because they affect the global scope.@babel/plugin-transform-runtime
approach is nice but it does not currently supports targets like@babel/preset-env
.Input Code
Babel/Babylon Configuration (.babelrc, package.json, cli command)
Current Behavior
Expected Behavior
Possible Solution
Maybe a new setting in
@babel/preset-env
which would act similarly touseBuiltIns
but without polluting the global scope, like@babel/plugin-transform-runtime
does.Context
Your Environment
The text was updated successfully, but these errors were encountered: