Uncaught ReferenceError: regeneratorRuntime is not defined in React

Abhijeet picture Abhijeet · May 12, 2020 · Viewed 10.4k times · Source

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

Answer

Julian Tellez picture Julian Tellez · Sep 27, 2020
  • 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