close

[Solved] ReferenceError: regeneratorRuntime is not defined in Babel 7

Hello Guys, How are you all? Hope You all Are Fine. Today I get the following error ReferenceError: regeneratorRuntime is not defined in Babel 7 nodejs. 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 ReferenceError: regeneratorRuntime is not defined in Babel 7 Error Occurs?

I get the following error when I try to build/run my node application.

dist/index.js:314 regeneratorRuntime.mark(function _callee(productId) { ^

ReferenceError: regeneratorRuntime is not defined

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

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

    To Solve ReferenceError: regeneratorRuntime is not defined in Babel 7 Error This is how I solved it. Install plugin-transform-runtime. Add plugin-transform-runtime to the plugin's list in the .babelrc file.

  2. ReferenceError: regeneratorRuntime is not defined in Babel 7

    To Solve ReferenceError: regeneratorRuntime is not defined in Babel 7 Error This is how I solved it. Install plugin-transform-runtime. Add plugin-transform-runtime to the plugin's list in the .babelrc file.

Solution 1

If you are using Babel 7.4.0 or newer, then @babel/polyfill has been deprecated. Instead, you will want to use the following at the top of your main js file (likely index.js or similar):

import "core-js/stable";
import "regenerator-runtime/runtime";

Install these packages either with npm:

npm install --save core-js
npm install --save regenerator-runtime    

or with yarn:

yarn add core-js
yarn add regenerator-runtime

Solution 2

I just encountered this problem and came across the following solution:

In package.json I had @babel/polyfill as a dependency. However, in my index.js (My main js file) I had neglected to place the following line at the top:

import '@babel/polyfill'

Once I imported it, everything worked fine.

I did not need to install babel-runtime as other answers are suggesting.

Solution 3

Basically, you need babel runtime (NOT as a dev dependency) and the plugin transform-runtime

yarn add @babel/runtime 
yarn add -D @babel/plugin-transform-runtime

And, in .babelrc, add:

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

Solution 4

This is how I solved it:

Install plugin-transform-runtime:

npm install @babel/plugin-transform-runtime -D

Add plugin-transform-runtime to the plugin’s list in the .babelrc file:

{
  "presets": [
    "@babel/preset-env",
    "@babel/preset-react"
  ],
  "plugins": [
    ["@babel/transform-runtime"]  // <= Add it here
  ]  
}

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? Thank You.

Also, Read

Leave a Comment