I'm trying to use async, await from scratch on Babel 6, but I'm getting regeneratorRuntime is not defined.
.babelrc file
{
"presets": [ "es2015", "stage-0" ]
}
package.json file
"devDependencies": {
"babel-core": "^6.0.20",
"babel-preset-es2015": "^6.0.15",
"babel-preset-stage-0": "^6.0.15"
}
.js file
"use strict";
async function foo() {
await bar();
}
function bar() { }
exports.default = foo;
Using it normally without the async/await works just fine. Any ideas what I'm doing wrong?
Alternatively, if you don't need all the modules
babel-polyfill
provides, you can just specifybabel-regenerator-runtime
in your webpack config:When using webpack-dev-server with HMR, doing this reduced the number of files it has to compile on every build by quite a lot. This module is installed as part of
babel-polyfill
so if you already have that you're fine, otherwise you can install it separately withnpm i -D babel-regenerator-runtime
.Update your
.babelrc
file according to the following examples, it will work.If you are using
@babel/preset-env
packageMy simple solution:
.babelrc
I had a setup
with webpack using
presets: ['es2015', 'stage-0']
and mocha that was running tests compiled by webpack.
To make my
async/await
in tests work all I had to do is addmocha --require babel-polyfill
option.I get this error using gulp with rollup when I tried to use ES6 generators:
I may case the solution was to include
babel-polyfill
as bower component:and add it as dependency in index.html:
i had regeneratorRuntime is not defined error when i used 'async' and 'await' in my react app 'async' and 'await' is a new keywords in ES7 for that you should use babel-preset-es2017 install this devDependencies:
`
and use this
"presets": [ "es2017" , "stage-0" , "react" ]