close

[Solved] Babel ReferenceError: regeneratorRuntime is not defined

Hello Guys, How are you all? Hope You all Are Fine. Today I am facing the Following error in my project Babel ReferenceError: regeneratorRuntime is not defined in Javascript. So Here I am Explain to you all the possible solutions here.

Without wasting your time, Let’s start This Article to Solve This Error.

How Babel ReferenceError: regeneratorRuntime is not defined Error Occurs ?

I am trying t use the async-await function But I am facing the following error.


ReferenceError: regeneratorRuntime is not defined

How To Solve Babel ReferenceError: regeneratorRuntime is not defined Error ?

  1. How To Solve Babel ReferenceError: regeneratorRuntime is not defined Error?

    To Solve Babel 6 ReferenceError: regeneratorRuntime is not defined Error Here babel-polyfill is Required You have to install babel-polyfill to get async/await working. Install babel-polyfill by this command. npm i -D babel-core babel-polyfill babel-preset-es2015 babel-preset-stage-0 babel-loader

  2. Babel ReferenceError: regeneratorRuntime is not defined

    To Solve Babel 6 ReferenceError: regeneratorRuntime is not defined Error Here babel-polyfill is Required You have to install babel-polyfill to get async/await working. Install babel-polyfill by this command. npm i -D babel-core babel-polyfill babel-preset-es2015 babel-preset-stage-0 babel-loader

Solution 1: babel-polyfill is Required

Here babel-polyfill is Required You have to install babel-polyfill to get async/await working. Install babel-polyfill by this command.

npm i -D babel-core babel-polyfill babel-preset-es2015 babel-preset-stage-0 babel-loader

Here is 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"
}

babel-polyfill (deprecated as of Babel 7.4) is required. You must also install it in order to get async/await working.

npm i -D babel-core babel-polyfill babel-preset-es2015 babel-preset-stage-0 babel-loader

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";
}

Solution 2: use babel-plugin-transform-runtime inOrder to support async/await

Here use babel-plugin-transform-runtime inOrder to support async/await It also includes support for async/await along with other built-ins of ES 6.

$ npm install --save-dev babel-plugin-transform-runtime

In .babelrc, add the runtime plugin

{
  "plugins": [
    ["transform-runtime", {
      "regenerator": true
    }]
  ]
}

Solution 3: For Babel 7 User

 For Babel 7, install these two dependencies:

npm install --save @babel/runtime 
npm install --save-dev @babel/plugin-transform-runtime

And, in .babelrc, add:

{
    "presets": ["@babel/preset-env"],
    "plugins": [
        ["@babel/transform-runtime"]
    ]
}

Summery

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you?

Also, Read

Please Rate Our Solution to Motivate Us For Give Our Best

Leave a Comment