-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
[Documentation-Bug]: Can @babel/plugin-transform-runtime be used together with useBuiltIns ? #16149
Comments
Hey @qiulang! 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. |
This is what these plugins/presets do:
As you can see, there is an overlap in what the two plugins can do. To avoid confusion, we are moving towards a model where plugins are handled by a separate package:
|
@nicolo-ribaudo thanks for replying to me. I know So with your answer, can we draw the conclusions that:
My following setting is okay.
|
That configuration is correct, with a caveat: On the other hand, if you inject polyfills through |
I read JMarkoski's words in #9853 again and realized his reason for "NO", "You need a way to transpile the babel helpers, and that's not good." was actually what you just said "with a caveat: @babel/plugin-transform-runtime will inject imports to @babel/runtime, and some of the files of @babel/runtime might need some polyfills in old browsers. " And zloirock also said there "as transform-runtime injects helpers and some helpers depends on globals which should be polyfilled." So if I use |
@nicolo-ribaudo zloirock also said (in 2019 but quoted in many places) in #9853 (comment)
While you said in #14443 (reply in thread)
|
To @nicolo-ribaudo:
Does the new model with
Sincerely, |
@nyngwang Unfortunately not yet -- for now, if you need to add polyfills for
I'm working on something to make |
I'm in a similar situation, and I figured out that my production code breaks when I have this configuration:
What I mean is that Webpack is able to build it, but I get a runtime error in the browser which I'm not able to track, from one of the bundles.
So at this point the alternatives are either removing
or removing the corejs from
So I have a question: which are the differences between the two? I've seen that the code size grows with the first option, so I tend towards the second one, but I would like to know which are the pros and cons. |
@gtempesta-pixartprinting Let me1 save you a week with a link for a (IMOO, the only) clean summary: https://github.com/babel/babel-polyfills/?tab=readme-ov-file#history-and-motivation. If you need my own words: Since you are probably not writing a library, follow your instinct:
And you can (I guess that you haven't) read the comment above which mentioned the new way recommended by one of the maintainers:
Footnotes
|
@nicolo-ribaudo @nyngwang I hit another transpile vs polyfill problem that I am desperate to need some help, can you guys take a look ? useBuiltIns: 'usage' will only transpile but not polyfill my nuxt v2 app Thanks a lot. |
@nyngwang Ok so I will stick to the second configuration. Thank you for the explanation. |
💻
How are you using Babel?
babel-loader (webpack)
Input code
Sorry, this is really not a bug but a question but I have asked at #16127 and #16145 but I didn't get an answer.
https://babeljs.io/docs/babel-plugin-transform-runtime is confusing about whether it can be used with
useBuiltIns
.On one hand, it says, "use @babel/preset-env's useBuiltIns option."
On the other hand, It says "When this plugin is enabled, the useBuiltIns option in @babel/preset-env must not be set. "
So what does "When this plugin is enabled" mean? I thought putting it in
bable.config.json
is to enable it.Configuration file name
babel.config.json
Configuration
Current and expected behavior
I use them together and I didn't find a problem.
Environment
Possible solution
No response
Additional context
I can't find a definite answer for it, e.g. stackoverflow has answers that do NOT agree with each other.
The comment from JMarkoski in #9853, which is quoted in many places say this,
But I have use
"plugins": [["@babel/plugin-transform-runtime", {}]]
together with"useBuiltIns": "usage"
all the time and I did not experience any problem while with a smaller bundled file size.The text was updated successfully, but these errors were encountered: