Babel7 ES and async/await


#1

I’m trying to use async/await with a fresh project with aurelia cli (babel7, es, and the new aurelia bundler…)

But I’m getting the nasty "ReferenceError: regeneratorRuntime is not define ".

Looking out there in the docs of babel I have added to .babelrc.js plugins:

return {
“plugins”: [
[’@babel/plugin-transform-runtime’,
{
“corejs”: false,
“helpers”: true,
“regenerator”: true,
“useESModules”: false
}]

but it’s not working…any ideas?


#2

Did you try to add babel polyfill? A google for "ReferenceError: regeneratorRuntime is not define" shows a lot of results related to missing babel polyfill


#3

Not sure how to do it in au CLI but here is an example with webpack. Perhaps that can give you a clue…


#4

Hi, in your main.js or main.ts file, add
import ‘babel-polyfill’;

Regards,


#5

With babel7, it is import '@babel/polyfill';.


#6

Hey guys, thank you all for the answers… but none of them worked for me.

I have left it for the moment because I have other priorities … and in the end I will also convert all the code to typescript.


#7

@jrogalan would you mind to open an issue in cli github repo? I will try to fix the skeleton after my vacation.


#8

Awesome @huochunpeng ,

Thanks!


#9

Hi @jrogalan,
I managed to get async await working with by adding this to prepend in aurelia.json

aurelia.json


“name”: “vendor-bundle.js”,
“prepend”: [
"node_modules/@babel/polyfill/dist/polyfill.min.js",
“node_modules/bluebird/js/browser/bluebird.core.js”,


#10

@LetsZiggy thank you! its works like a charm… :money_mouth_face: