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.

es7.promise.finally polyfill definition gets nuked by es6.promise polyfill

See original GitHub issue

Bug Report

Current Behavior Using latest @babel/core, and @babel/transform-runtime (7.3.4) with useBuiltIns: 'usage' set. It appears the the correct polyfills are being applied, however due to the order in which the require statements get generated, the polyfill definition for es7.promise.finally gets nuked by the es6.promise definition.

Expected behavior/code es7.promise.finally seems to extend native promise but loading es6.promise nukes the extension which then throws error in .finally() usage.

Babel Configuration (.babelrc, package.json, cli command)

Relevant config:

{
    presets: [
        [('@babel/preset-env'),
        {
            debug: true,
            modules: false,
            targets: {
                ie: '11'
            },
            useBuiltIns: 'usage'
        }],
        '@babel/preset-react'
    ],
        plugins: [
            ['@babel/plugin-transform-runtime',
                {
                    useESModules: true,
                    helpers: true
                }
            ]
        ]
}

Environment

  • Babel version(s): 7.3.4
  • Node/npm version: 10.x LTS
  • How you are using Babel: webpack + babel-loader with babel.config.js

Possible Solution Unclear from my searching if there is a way to order the polyfills. I’ve tried explicitly using “include” and passing in es6.promise followed by es7.promise.finally but seems to make no difference. Current workaround is to add the following to exclude and add them manually, in proper order to my entry point, e.g.

babel.config.js

...
 [('@babel/preset-env'),
        {
            debug: true,
            modules: false,
            exclude: ['es7.promise.finally', 'es6.promise'],
            targets: {
                ie: '11'
            },
            useBuiltIns: 'usage'
        }],
...

entry.js

import 'core-js/modules/es6.promise';
import 'core-js/modules/es7.promise.finally';
...

/edit: Adding sample section of generated imports as they appear in final output in “incorrect” order

// EXTERNAL MODULE: [omitted]/node_modules/core-js/modules/es7.promise.finally.js
var es7_promise_finally = __webpack_require__("../../node_modules/core-js/modules/es7.promise.finally.js");

// EXTERNAL MODULE: [omitted]/node_modules/@babel/runtime/helpers/esm/typeof.js
var esm_typeof = __webpack_require__("../../node_modules/@babel/runtime/helpers/esm/typeof.js");

// EXTERNAL MODULE: [omitted]/node_modules/tslib/tslib.es6.js
var tslib_es6 = __webpack_require__("../../node_modules/tslib/tslib.es6.js");

// EXTERNAL MODULE: [omitted]/node_modules/core-js/modules/es6.array.iterator.js
var es6_array_iterator = __webpack_require__("../../node_modules/core-js/modules/es6.array.iterator.js");

// EXTERNAL MODULE: [omitted]/node_modules/core-js/modules/es6.string.iterator.js
var es6_string_iterator = __webpack_require__("../../node_modules/core-js/modules/es6.string.iterator.js");

// EXTERNAL MODULE: [omitted]/node_modules/core-js/modules/web.dom.iterable.js
var web_dom_iterable = __webpack_require__("../../node_modules/core-js/modules/web.dom.iterable.js");

// EXTERNAL MODULE: [omitted]/node_modules/@babel/runtime/regenerator/index.js
var regenerator = __webpack_require__("../../node_modules/@babel/runtime/regenerator/index.js");
var regenerator_default = /*#__PURE__*/__webpack_require__.n(regenerator);

// EXTERNAL MODULE: [omitted]/node_modules/core-js/modules/es6.promise.js
var es6_promise = __webpack_require__("../../node_modules/core-js/modules/es6.promise.js");

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
zloirockcommented, Mar 19, 2019

This PR will be landed in next some days. You already wrote a simple own workaround and it should work fine.

1reaction
zloirockcommented, Mar 19, 2019

Fixed in #7646 with corejs: 3 option.

Read more comments on GitHub >

github_iconTop Results From Across the Web

promise-polyfill - npm
Lightweight promise polyfill. A+ compliant. Latest version: 8.2.3, last published: 9 months ago. Start using promise-polyfill in your ...
Read more >
Promise.finally() polyfill - LearnersBucket
Learn how to implement the polyfill for promise.finally(), which is executed after the promise is settled or fulfilled.
Read more >
Babel-polyfill Promises and "finally" support - Stack Overflow
I believe, the Babel-Polyfill shim uses core-js under the hood, which does support Promise.finally: https://github.com/zloirock/core-js#commonjs.
Read more >
angular/angular - Gitter
I think it was a console error - there's no way it could be real. I still think they should reimburse me for...
Read more >
doc - Apple Open Source
Implement ES6 Promise and related abstract operations in builtins JS 2. ... PICTURE_SIZES because it causes problems with out of date <picture> 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