Redundant polyfills added for IE11 with useBuiltIns: usage
See original GitHub issueBug Report
Current behavior Targetting default browsers includes polyfills for IE11 which are useless according to Can I Use. I see these polyfills added
es.array.for-each { “ie”:“11” } web.dom-collections.for-each { “ie”:“11” } es.array.filter { “ie”:“11” } es.array.map { “ie”:“11” } es.array.slice { “ie”:“11” }
Input Code
export class Application {
constructor(win) {
this.window = win
this.init = this.init.bind(this)
this.applyFunc = this.applyFunc.bind(this)
}
init() {
this.queue = [1, 2, 3]
this.queue = this.queue.filter((el) => el > 1).map(el => el * 9)
}
applyFunc() {
try {
var args = (arguments.length === 1 ? [arguments[0]] : Array.apply(null, arguments))
var funcArgs = args.slice(1)
var funcName = args[0]
if (funcName === 'initialize') {
this.init.apply(this, funcArgs)
}
} catch (err) {
funcName = args[0]
console.log(`Error occurred trying to run the function ${funcName}: `, err)
}
}
}
Expected behavior based on this can I use for Array filter link and others relate to forEach and map and slice these polyfills are not supposed to be included
Babel Configuration (babel.config.js, .babelrc, package.json#babel, cli command, .eslintrc)
{
{
"presets": [
[
"@babel/env",
{
"debug": true,
"useBuiltIns": "usage",
"corejs": "3.6.5",
"modules": false,
"bugfixes": true,
"targets": "defaults"
}
]
]
}
}
Environment
System:
OS: macOS 10.15.4
Binaries:
Node: 12.14.0 - /usr/local/bin/node
Yarn: 1.16.0 - /usr/local/bin/yarn
npm: 6.13.4 - /usr/local/bin/npm
npmPackages:
@babel/cli: ^7.10.1 => 7.10.1
@babel/core: ^7.10.2 => 7.10.2
@babel/preset-env: ^7.10.2 => 7.10.2
babel-loader: ^8.1.0 => 8.1.0
webpack: ^4.43.0 => 4.43.0
- How you are using Babel: [
loader
]
Additional context Add any other context about the problem here. Or a screenshot if applicable
Issue Analytics
- State:
- Created 3 years ago
- Comments:13 (4 by maintainers)
Top Results From Across the Web
Babel adding unnecessary core-js polyfills for IE11
In my app, I have configured Babel to add Core-JS polyfills, but it seems to be adding unnecessary polyfills.
Read more >How to load polyfills only when needed
I know three ready-to-use approaches for that: polyfill.io; the module / nomodule pattern; the useBuiltIns option in @babel/preset-env ...
Read more >Babel With Core-Js - Polyfills Not Ie11 Compatible - ADocLib
Babel includes a polyfill that includes a custom regenerator runtime and corejs. ... Redundant polyfills added for IE11 with useBuiltIns: usage #11713.
Read more >Babel, JavaScript Transpiling And Polyfills | Getaround Tech
Babel uses plugins to be as modular as possible (example: ... see polyfills handling section below useBuiltIns: "usage", // "entry", ...
Read more >Serve modern code to modern browsers for faster page loads
To import specific polyfills needed for the target browsers, add a ... to browsers directly without the use of any unnecessary polyfills.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Is there any alternative compatibility tables that we can use, that is not so incredibly strict. There’s good data in https://github.com/mdn/browser-compat-data and https://github.com/kangax/compat-table - it would then need to be mapped to this naming syntax
Looks like it used to use Kangax’s compat table - https://github.com/babel/babel-preset-env/issues/7
It also does look like the core-js-compat allows for some configuration of aggressiveness - but it would require manually adding every single polyfill you would like to use natively instead of polyfill, which doesn’t help much when you want it automatically with useBuiltins: ‘usage’
Edit: I’ve rolled back to 7.3.4 which uses Kangax compat table, instead of the aggressive core-js-compat
This works way better for me - not so many unnecessary polyfills. Array.map and Array.reduce is then not polyfilled 🎉
"@babel/core": "7.3.4", "@babel/preset-env": "7.3.4",
I’d suggest going back to this @nicolo-ribaudo
Based on @jtwee’s link above, this seems to be related to “fixing early implementations of
Array#{ every, forEach, reduce, reduceRight, some }
for usage ofToLength
”.Since my code (using
[].forEach
) does not seem to rely on this, I have decided to extend the@babel/preset-env
config with the following: