fast-async icon indicating copy to clipboard operation
fast-async copied to clipboard

Babel 7 "useRuntimeModule"

Open rkumorek opened this issue 6 years ago • 4 comments

Hey,

I am running into an issue when I write for...of loop with await. (example). I am transpiling to ES5 with babel and I believe I need nodent-runtime to have that code running. When I add useRuntimeModule: true to babel config I get this error: [dev:build] Error: This API has been removed. If you're looking for this functionality in Babel 7, you should import the '@babel/helper-module-imports' module and use the functions exposed from that module, such as 'addNamed' or 'addDefault'.

I've tried adding @babel/helper-module-imports but couldn't make it work, not sure exactly how should I use it ;( Is there a way I can make it work with fast-async and babel 7?

Edit: What I just found out is it runs those async functions in the loop but anything that's after the loop not invoked. :/

....
// everything runs before
for (const hook of this.hooks.before) {
    await hook(); // this run
}
await asyncFunction(); // this doesn't run

rkumorek avatar May 22 '19 17:05 rkumorek

For Babel v7.x.x install fast-async@7 - although I haven't used it for over a year when Babel7 was in beta - it's possible they've changed the plugin API since it was written

The code basically runs for me. You can see it working (without Babel) here:

http://nodent.mailed.me.uk/#async%20function%20done()%20%7B%20console.log(%22done%22)%20%7D%0A%0Aconst%20hooks%20%3D%20%5B%0A%20%20%20%20async%20()%20%3D%3E%20console.log(%22one%22)%2C%0A%20%20%20%20async%20()%20%3D%3E%20console.log(%22two%22)%2C%0A%20%20%20%20async%20()%20%3D%3E%20console.log(%22three%22)%2C%0A%5D%0A%2F%2F%20everything%20runs%20before%0Afor%20(const%20hook%20of%20hooks)%20%7B%0A%20%20%20%20await%20hook()%3B%20%2F%2F%20this%20run%0A%7D%0Aawait%20done()%3B%20%2F%2F%20this%20doesn't%20run%0A%0A~options~%7B%22mode%22%3A%22lazyThenables%22%2C%22promiseType%22%3A%22Zousan%22%2C%22noRuntime%22%3Afalse%2C%22es6target%22%3Afalse%2C%22wrapAwait%22%3Afalse%2C%22spec%22%3Afalse%7D

matAtWork avatar Jun 17 '19 14:06 matAtWork

Thanks for response. I do have issue when using ky. It stops executing on this for...of loop https://github.com/sindresorhus/ky/blob/master/index.js#L226 and https://github.com/sindresorhus/ky/blob/master/index.js#L319

It is pretty much the same as our examples so I am not sure why would it fail. Any ideas? Also after some more testing I had other async for...of loops working... except of ky loops.

// EDIT:

Oh my. I've been using fast-async 6.3. Upgraded to @7 and it works. Yay! Thanks for help and for fast-async :) You can close the issue.

rkumorek avatar Jun 17 '19 14:06 rkumorek

Well, tried it again and after transpiling ky I still can't get it working on IE11 :( Guess I won't be able to use that package yet.

rkumorek avatar Jun 20 '19 22:06 rkumorek

IE 11 doesn't have promises, so you might need to include a promise polyfill to get this to work in IE11.

patrick-mcdougle avatar Aug 27 '19 18:08 patrick-mcdougle