I\'m trying to use async, await from scratch on Babel 6, but I\'m getting regeneratorRuntime is not defined.
.babelrc file
{
\"presets\": [ \"es2
It works if you set the target to Chrome. But it might not work for other targets, please refer to: https://github.com/babel/babel-preset-env/issues/112
So this answer is NOT quite proper for the original question. I will keep it here as a reference to babel-preset-env
.
A simple solution is to add import 'babel-polyfill'
at the beginning of your code.
If you use webpack, a quick solution is to add babel-polyfill
as shown below:
entry: {
index: ['babel-polyfill', './index.js']
}
Check this project: https://github.com/babel/babel-preset-env
yarn add --dev babel-preset-env
Use the following as your babel configuration:
{
"presets": [
["env", {
"targets": {
"browsers": ["last 2 Chrome versions"]
}
}]
]
}
Then your app should be good to go in the last 2 versions of Chrome browser.
You can also set Node as the targets or fine-tune the browsers list according to https://github.com/ai/browserslist
I really like babel-preset-env
's philosophy: tell me which environment you want to support, do NOT tell me how to support them. It's the beauty of declarative programming.
I've tested async
await
and they DO work. I don't know how they work and I really don't want to know. I want to spend my time on my own code and my business logic instead. Thanks to babel-preset-env
, it liberates me from the Babel configuration hell.