Skip to content
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

Using `@babel/runtime-corejs*` still uses the global Promise for generators/async-fns #10678

Open
loganfsmyth opened this issue Nov 8, 2019 · 7 comments
Labels

Comments

@loganfsmyth
Copy link
Member

@loganfsmyth loganfsmyth commented Nov 8, 2019

I thought this was something we'd addressed at some point, but I guess not?

regenerator-runtime uses the global Promise, even if we're trying to use it via one of the standalone runtime modules like @babel/runtime-corejs3. In an ideal world, we'd be able to pass in the Promise implementation that the regenerator runtime should use, or else transform the regenerator runtime at publish time and include a copy of it inside the babel runtime, or something.

@mreinstein

This comment has been minimized.

Copy link

@mreinstein mreinstein commented Nov 8, 2019

I was definitely burned on this. here is a minimal repro example.

https://github.com/mreinstein/babel-async-min-example

To reproduce the problem:

  1. clone this repo
  2. comment out these lines: https://github.com/mreinstein/babel-async-min-example/blob/master/rollup.config.js#L14-L34 (this is a workaround for the problem that @loganfsmyth produced)
  3. npm run build
  4. open index.html in a browser that lacks Promise support (ie 11 for example)
  5. notice the console error about Promise being undefined.
@nicolo-ribaudo

This comment has been minimized.

Copy link
Member

@nicolo-ribaudo nicolo-ribaudo commented Nov 8, 2019

cc @benjamn What do you think that would be best to do?

@MarcelGerber

This comment has been minimized.

Copy link

@MarcelGerber MarcelGerber commented Nov 8, 2019

I actually have a test case that worked fine in Babel 7.6.2, but is broken with Babel 7.7.2.
You can find this test case in https://github.com/MarcelGerber/babel-bug-regenerator-promise. There is a working branch using 7.6.2, while the master branch is not working (7.7.2).
The diff between these two branches (including the built file!) can be seen here: MarcelGerber/babel-bug-regenerator-promise@working...master

See also: The README

Environment

  • Babel version(s): 7.7.2 (broken), 7.6.2 (working)
  • Node/npm version: 10.17.0
  • OS: Windows 10
  • How you are using Babel: Webpack babel-loader

IE11 complains about this Promise call: https://github.com/MarcelGerber/babel-bug-regenerator-promise/blob/6687cfca00423eac3fa6b2c6d95b30e57bde5015/build/index.js#L3279

@MarcelGerber

This comment has been minimized.

Copy link

@MarcelGerber MarcelGerber commented Nov 8, 2019

This (at least my) problem is caused by #9481. Disabling the async-to-generator step makes it such that global Promise is used in the code generated by regenerator.

@nicolo-ribaudo

This comment has been minimized.

Copy link
Member

@nicolo-ribaudo nicolo-ribaudo commented Nov 9, 2019

@MarcelGerber / @mreinstein
Could you comment out these lines?
https://github.com/nicolo-ribaudo/babel/blob/f087c3f5bbcafd6d9689f261798ae809b9fb4fcc/packages/babel-preset-env/data/overlapping-plugins.js#L6-L7

I want to keep the logic because it will be useful in the future for something we are working on and because I'd like to avoid using async-to-generators when we already use regenerator, but let's fix the regression for now.

@MarcelGerber

This comment has been minimized.

Copy link

@MarcelGerber MarcelGerber commented Nov 9, 2019

@nicolo-ribaudo Yes, that's exactly what I did yesterday. With these two lines commented out everything works just fine.

@benjamn

This comment has been minimized.

Copy link
Contributor

@benjamn benjamn commented Nov 10, 2019

Is this an application-level concern, such that setting regeneratorRuntime.Promise once, in some sort of global setup code, might be a good solution, or would it make more sense to allow passing a specific Promise implementation to each regeneratorRuntime.async call (once per async function, essentially)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants
You can’t perform that action at this time.