@babel/plugin-transform-runtime bring unnecessary polyfill with corejs configuration.

Bug Report

  • I would like to work on a fix!

Current Behavior
I use @babel/preset-env and @babel/plugin-transform-runtime, both set 3 to corejs option. and I set high chrome target version. But, compile results still have needless polyfill.

Input Code

// source
new Promise(() => null);



// .browserslistrc
Chrome >= 78



// .babelrc
{
  "presets": [
    [
      "@babel/preset-env",
      {
        "spec": false,
        "loose": false,
        "useBuiltIns": "usage",
        "corejs": 3,
        "modules": "commonjs"
      }
    ]
  ],
  "plugins": [
    [
      "@babel/plugin-transform-runtime",
      {
        "corejs": 3,
        "helpers": true,
        "regenerator": true,
        "useESModules": false
      }
    ]
  ]
}



// output
"use strict";

var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault");

var _promise = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/promise"));

new _promise.default(function () {
  return null;
});

As seen examples, chrome 78 is supprted Promise, but babel still bring it’s polyfill. If I remove @babel/plugin-transform-runtime corejs option, it work correctly.

Expected behavior/code
Following output is mine expected result.

// output
"use strict";

new Promise(() => null);

Environment

  • Babel version(s): 7.9.6
  • Node/npm version: Node 12.13.0/npm 6.12.0
  • OS: Windows 10
  • Monorepo: no
  • How you are using Babel: cli

Possible Solution

Additional context/Screenshots
None.

1 possible answer(s) on “@babel/plugin-transform-runtime bring unnecessary polyfill with corejs configuration.

  1. First, you should not be using @babel/preset-env and @babel/transform-runtime together, see here #9853 (comment) for a thorough answer. The reason babel is including the polyfills is because the @babel/transform-runtime plugin doesn’t have an option to specify targets, so it will polyfill every possible feature.