[Solved] Babel 6 regeneratorRuntime is not defined
React JS
Mohit Mozumder
Problem:
While working with React and Parcel bundler I got an error-
regeneratorRuntime is not defined
Solution 1:
First of all install regenerator-runtime
npm install --save regenerator-runtime
Then update webpack fileentry: ["regenerator-runtime/runtime.js", "<your enter js file>"]
require import 'regenerator-runtime/runtime'
at the top of the file that you're using async function
Solution 2:
To solve this problem babel-polyfill is Required So you have to install babel-polyfill to get async/await working by this command.
npm i -D babel-core babel-polyfill babel-preset-es2015 babel-preset-stage-0 babel-loader
Your Package.json
"devDependencies": {
"babel-core": "^6.0.20",
"babel-polyfill": "^6.0.16",
"babel-preset-es2015": "^6.0.15",
"babel-preset-stage-0": "^6.0.15"
}
.babelrc
{
"presets": [ "es2015", "stage-0" ]
}
Now you can use async await like this. Here is my example.
"use strict";
export default async function foo() {
var s = await bar();
console.log(s);
}
function bar() {
return "bar";
}
Thank you for reading the article. If you face any further issue feel free to ask us.