Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Uncaught ReferenceError: regeneratorRuntime is not defined in React

I'm getting an error "Uncaught ReferenceError: regeneratorRuntime is not defined". Please help me to find out the error and how to resolve it.

enter image description here

like image 676
Abhijeet Avatar asked May 12 '20 15:05

Abhijeet


People also ask

What is regenerator-runtime runtime?

regenerator-runtime is the runtime support for compiled/transpiled async functions. (It may well have other uses, but this is the predominant one.)


1 Answers

  • Install the runtime dependency
npm i --save-dev @babel/plugin-transform-runtime
  • Add the plugin to your .babelrc file
{
  "plugins": ["@babel/plugin-transform-runtime"]
}

More Info: https://babeljs.io/docs/en/babel-plugin-transform-runtime

TLDR;

  • Async functions are abstraction on top of generators.
  • Async functions and generators are now supported in all major browsers and in Node10 and upwards.
  • If you are using a transpiler (such as babel) for backwards compatibility, you would need an extra "layer" that transforms generators. This implies transforming ES6 into ES5 at runtime since their syntax isn't backwards compatible. See https://cmichel.io/how-are-generators-transpiled-to-es5
like image 63
Julian Tellez Avatar answered Oct 05 '22 10:10

Julian Tellez