Uncaught ReferenceError: regeneratorRuntime is not defined in React Uncaught ReferenceError: regeneratorRuntime is not defined in React reactjs reactjs

Uncaught ReferenceError: regeneratorRuntime is not defined in React


  • 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


Thanks It works when I add an import statement -- import regeneratorRuntime from "regenerator-runtime"; in the component i am using async/await.


Ran into this problem (using Babel v7) and even after following the advice and installing relevant packages, I was still unable to get id of this error. following stack overflow posts were checked...

Following actions helped:

  1. Go to package.json & add the following inside 'jest' (screenshot added also):

"moduleNameMapper": {
".+\.(css|styl|less|sass|scss|png|jpg|ttf|woff|woff2)$":"identity-obj-proxy" }

enter image description here

  1. when running a test use the following suffix in the command...

--setupFilesAfterEnv "./src/setupTests.js"

so to run a test, it will be:

$ jest /pathToTest/TestFile.test.js --setupFilesAfterEnv"./src/setupTests.js"

Hope it helps someone like it helped me...