question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Redundant polyfills added for IE11 with useBuiltIns: usage

See original GitHub issue

Bug 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:closed
  • Created 3 years ago
  • Comments:13 (4 by maintainers)

github_iconTop GitHub Comments

4reactions
and-poulsencommented, Jun 25, 2020

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

0reactions
backflipcommented, Dec 27, 2020

Based on @jtwee’s link above, this seems to be related to “fixing early implementations of Array#{ every, forEach, reduce, reduceRight, some } for usage of ToLength”.

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:

exclude: ['es.array.for-each']
Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found