`regeneratorRuntime` is not defined when running Jest test

jest regenerator-runtime
regeneratorruntime is not defined nextjs
regeneratorruntime is not defined typescript
regeneratorruntime is not defined redux
regeneratorruntime is not defined react-native

The title pretty much explains what I'm facing. I'm trying to test a React component that has some state, and I attempt to provide my store to the component in order to get what it needs. When I run the test of the component using Jest, I get the following error:

ReferenceError: regeneratorRuntime is not defined

I've determined through some reading that this is caused by babel-polyfill or regenerator-runtime not being applied correctly to Jest. However, I've tried installing both of those packages and re-running with no change in results. After reading the Jest Github issues page (Remove auto-inclusion of babel-polyfill #2755), I found out that babel-polyfill is not included automatically by Jest as of version 19. My manual installation of that package should have fixed the issue, but it did not. I've included some of the files that I think are relevant


  "presets": ["es2015", "react", "stage-2"],
  "env": {
    "development": {
      "plugins": [
        ["react-transform", {
          "transforms": [{
            "transform": "react-transform-hmr",
            "imports": ["react"],
            "locals": ["module"]


    "transform": {
        "^.+\\.(js|jsx)$": "<rootDir>/node_modules/webpack-babel-jest",
        ".*\\.(vue)$": "<rootDir>/node_modules/jest-vue-preprocessor",
        ".*": "babel-jest"
    "moduleNameMapper": {
        "\\.(jpg|jpeg|css|scss|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "<rootDir>/__tests__/__mocks__/fileMock.js",
        ".*\\.(vue)$": "vue/dist/vue.js"
    "testPathIgnorePatterns": ["type_parser.spec.js", 


  "name": "my_project",
  "version": "0.2.0",
  "description": "My Project",
  "scripts": {
    "clean:build": "node ./bin/clean.js createdir",
    "build:html": "node ./bin/buildHtml.js",
    "deployProduction": "node ./bin/deployProduction.js",
    "start": "webpack-dev-server --config ./config/webpack.config.dev.js --hot --inline --progress",
    "serve": "npm run deployProduction&& supervisor --watch ./production-copy src/js/server",
    "prebuild": "npm run clean:build",
    "postbuild": "node ./bin/postBuild.js",
    "rebuild-win": "set BUILD_TYPE=preview& npm run prebuild & npm run build-win & npm run serve",
    "build": "set BUILD_TYPE=final& npm run prebuild & npm run build-win",
    "deploy": "npm run build & npm run serve",
    "build-win": "set NODE_ENV=production & npm run element-build & npm run build-doc & npm run build:html &  webpack -p --config ./config/webpack.config.prod.js --json > webpack.log.json & npm run postbuild",
    "lint": "eslint config src/js/**/*.js",
    "jscs": "jscs src/js/",
    "test": "jest --no-cache --verbose --config=./__tests__/jest.config",
    "test:watch": "npm run test -- --watch",
    "element-init": "node node_modules/element-theme/bin/element-theme -i src/js/core/ui/element-theme.css",
    "element-build": "node node_modules/element-theme/bin/element-theme -c src/js/core/ui/element-theme.css -o src/js/core/ui/element-theme ",
    "build-doc": "node bin/buildDoc.js ",
    "storybook": "start-storybook -p 9001 -c .storybook"
  "repository": {
    "type": "git",
    "url": "my_url"
  "license": "MIT",
  "bugs": {
    "url": "my_url"
  "homepage": "my_homepage",
  "dependencies": {
    "autoprefixer": "^6.3.6",
    "axios": "^0.11.1",
    "babel-runtime": "^6.23.0",
    "babel-standalone": "^6.10.3",
    "bluebird": "^3.4.0",
    "brace": "^0.8.0",
    "browserify": "^13.0.1",
    "chai": "^3.5.0",
    "classnames": "2.2.3",
    "cls-bluebird": "^1.0.1",
    "codemirror": "^5.16.0",
    "connect-history-api-fallback": "^1.3.0",
    "continuation-local-storage": "^3.1.7",
    "dateformat": "^1.0.12",
    "diff": "^3.0.1",
    "element-theme": "^0.4.0",
    "element-ui": "^1.1.5",
    "express-history-api-fallback": "^2.0.0",
    "filedrop": "^2.0.0",
    "fs-extra": "^0.30.0",
    "history": "^2.0.2",
    "humps": "^1.0.0",
    "immutability-helper": "^2.1.1",
    "isomorphic-fetch": "^2.2.1",
    "json-loader": "^0.5.4",
    "jszip": "^3.0.0",
    "jszip-utils": "0.0.2",
    "material-ui": "^0.16.7",
    "materialize-css": "^0.97.6",
    "mocha": "^2.5.3",
    "moment": "^2.17.1",
    "normalizr": "^1.0.0",
    "raven-js": "^3.9.1",
    "react": "^15.0.1",
    "react-ace": "^3.5.0",
    "react-addons-update": "^15.4.2",
    "react-dom": "^15.0.1",
    "react-redux": "^4.4.5",
    "react-router": "^2.3.0",
    "react-router-redux": "^4.0.2",
    "redux": "^3.4.0",
    "redux-logger": "^2.6.1",
    "redux-saga": "^0.9.5",
    "request": "^2.72.0",
    "request-promise": "^3.0.0",
    "reselect": "^2.5.4",
    "save-as": "^0.1.7",
    "showdown": "^1.4.2",
    "three": "^0.79.0",
    "url-pattern": "^1.0.3",
    "vue": "^2.0.5",
    "vue-easy-slider": "^1.4.0",
    "vue-loader": "^9.8.1",
    "vue-router": "^2.0.1",
    "vue-slider-component": "^2.0.4",
    "walk": "^2.3.9"
  "devDependencies": {
    "@kadira/storybook": "^2.35.3",
    "babel-core": "^6.7.6",
    "babel-eslint": "^6.1.0",
    "babel-jest": "^18.0.0",
    "babel-loader": "^6.0.2",
    "babel-plugin-react-transform": "^2.0.2",
    "babel-polyfill": "^6.23.0",
    "babel-preset-es2015": "^6.22.0",
    "babel-preset-es2016": "^6.22.0",
    "babel-preset-react": "^6.23.0",
    "babel-preset-stage-2": "^6.5.0",
    "babel-register": "^6.7.2",
    "chai": "3.5.0",
    "chai-jquery": "2.0.0",
    "cheerio": "0.20.0",
    "colors": "1.1.2",
    "concurrently": "^2.0.0",
    "copy-webpack-plugin": "2.1.1",
    "css-loader": "0.23.1",
    "element-theme-default": "^1.1.5",
    "enzyme": "^2.7.1",
    "eslint": "^2.13.1",
    "eslint-config-airbnb": "^9.0.1",
    "eslint-plugin-import": "^2.2.0",
    "eslint-plugin-jsx-a11y": "^4.0.0",
    "eslint-plugin-react": "^5.2.2",
    "express": "^4.13.4",
    "extract-text-webpack-plugin": "1.0.1",
    "file-loader": "0.8.5",
    "identity-obj-proxy": "^3.0.0",
    "jest": "^19.0.2",
    "jest-cli": "^18.1.0",
    "jest-css-modules": "^1.1.0",
    "jest-enzyme": "^2.1.2",
    "jest-vue-preprocessor": "^0.1.2",
    "jquery": "2.2.3",
    "jscs": "3.0.3",
    "jsdoc-to-markdown": "^2.0.0",
    "jsdom": "8.4.0",
    "json-loader": "^0.5.4",
    "mocha": "^2.4.5",
    "ncp": "^2.0.0",
    "node-sass": "3.7.0",
    "postcss-loader": "0.8.2",
    "react-addons-test-utils": "^15.4.2",
    "react-hot-loader": "1.3.0",
    "react-test-renderer": "^15.4.2",
    "react-transform-hmr": "^1.0.4",
    "redux-devtools": "^3.3.1",
    "redux-devtools-dock-monitor": "^1.1.1",
    "redux-devtools-log-monitor": "^1.0.11",
    "regenerator-runtime": "^0.10.3",
    "remotedev": "^0.1.2",
    "rimraf": "^2.5.2",
    "sass-loader": "3.2.0",
    "storybook-addon-material-ui": "^0.7.6",
    "style-loader": "0.13.1",
    "url-loader": "0.5.7",
    "vueify": "^9.4.0",
    "webpack": "^1.13.0",
    "webpack-babel-jest": "^1.0.4",
    "webpack-dev-middleware": "^1.6.1",
    "webpack-dev-server": "^1.16.3",
    "webpack-hot-middleware": "^2.10.0"

I used import "babel-polyfill" and it solved my problem

facebook/jest, Unfortunately, when i run npm test , i get error of importing react-numpad as below: ReferenceError: regeneratorRuntime is not defined 3  I am now getting regeneratorRuntime is not defined without additional config required. Running jest from command line works as expected. Running jest from command line works as expected. Wallaby.js configuration file

In case you are using a setupTests.js file you can import regenerator-runtime from there:

// setupTests.js

import 'regenerator-runtime/runtime'
import Enzyme from 'enzyme'
import EnzymeAdapter from 'enzyme-adapter-react-16'

  adapter: new EnzymeAdapter()

  Then you can import setupTests.js to every test file or better yet, in your package.json just add setupFilesAfterEnv to the jest config:

// package.json

  "dependencies": {
  "devDependencies": {
  "jest": {
    "setupFilesAfterEnv": ["./pathToYour/setupTests.js"] 

  Don't forget to install the regenerator-runtime package:

$ yarn add regenerator-runtime

  There is no need to import the complete babel-polyfill (or @babel/polyfill if Babel ≥ v.7.0.0) that btw has been deprecated in favor of directly including core-js/stable and regenerator-runtime/runtime.

ReferenceError: regeneratorRuntime is not defined with Jest · Issue , Input Code React Component JS - DeleteAsset.js impo importing vue results in a "regeneratorRuntime is not defined" error #8724. Open. Auth0Context.js:145 Uncaught ReferenceError: regeneratorRuntime is not defined at eval (Auth0Context.js:145) at Auth0Provider (Auth0Context.js:193) at renderWithHooks (react-dom.development.js:16320) at mountIndeterminateComponent (react-dom.development.js:18735) at beginWork $1 (react-dom.development.js:20084) at HTMLUnknownElement.callCallback (react-dom.development.js:362) at Object

While importing babel-polyfill into each test worked, the Updated jest docs (v24) suggests setting this in your babel config. If you do this you should no longer need to import babel-polyfill. (Personally, I was missing the targets option from my preset-env config).

// babel.config.js
module.exports = {
  presets: [
        targets: {
          node: 'current',

A word to the wise: specifying targets will override any browserslist config you have defined (that babel would otherwise use). So in a web project, you'll probably want to create a dynamic babel.config.js that is "jest-aware" so that you're only adding targets when it's a test environment. See the section titled "Making your Babel config jest-aware" in the jest docs.

"regeneratorRuntime is not defined" error with async and , Tests fail with ReferenceError: regeneratorRuntime is not defined after babel.​config.js // NOTE: If you use this your tests aren't running exactly  I just bumped into this issue! @mpontus @okonet you can use jest@next where it's fixed or otherwise you need install babel-polyfill.. Jest used to autoinclude babel-polyfill (and still does it in 19.0.2), but since it caused memory leaks, we moved to using regenerator-runtime only, which ships with our transitive deps (so since Jest v20 if you're using npm >=3 or yarn you don't need to install

Latest solution as of 2 Oct 2019 is to import following in your setupTests.js file.

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

babel-polyfill is deprecated.

regenerator 0.13.1 breaks Jest · Issue #7579 · facebook/jest · GitHub, Finally, run yarn test and Jest will print this message: Note: Explicitly installing regenerator-runtime is not needed if you use npm 3 or 4 or Yarn using Babel's env option, keep in mind that Jest will automatically define NODE_ENV as test . Tests fail with ReferenceError: regeneratorRuntime is not defined after updating regenerator-runtime to 0.13.1. This is because regeneratorRuntime is no longer a global. facebook/regenerator#363. Per notes in that issue, we should be using @babel/plugin-transform-runtime now. Jest and its docs need to be updated accordingly.

With babel-core@bridge installed and @babel/core@7:

I solved the issue by adding the plugin @babel/plugin-transform-runtime and passing to my babel config the following:

 env: {
   test: {
     // ...
      plugins: [
        ['@babel/plugin-transform-runtime', {
          regenerator: true

Getting Started · Jest, However, according to the package.json, regenerator-runtime is installed so that should work too. Are you sure you're requiring/importing it correctly,  I still got the ReferenceError: regeneratorRuntime is not defined at the first then I realized it was because I didn't set the target. After setting the target for node I fix the regeneratorRuntime error:

Jest + Babel: regeneratorRuntime is not defined - javascript, When I run the test of the component using Jest, I get the following error: ReferenceError: regeneratorRuntime is not defined I've determined through some​  'Uncaught ReferenceError: regeneratorRuntime is not defined' makes added external packages and importing fonts in css not working in dockerized production build of feature/apollo-pure branch kriasoft/react-starter-kit#1892

`regeneratorRuntime` is not defined when running Jest test, I'm getting following error when trying to run an example from this directory: Test suite failed to run ReferenceError: regeneratorRuntime is not defined at Object. git clone https://github.com/facebook/jest jest cd jest/examples/async npm  Running npm run test does not seem to work regeneratorRuntime is not defined Thanks for contributing an answer to Stack Overflow!

jest, Facing issue to run the test case Code - import React from 'react'; import { render, fireEvent } from '@testing-library/react'; import… Using this method will selectively import those polyfills and the 'regenerator-runtime' file (fixing your regeneratorRuntime is not defined issue here) ONLY if they are needed by any of your target environments/browsers. If you using Gulp + Babel for a frontend you need to use babel-polyfill

  • "My manual installation of that package should have fixed the issue, but it did not." Are you importing the package anywhere? Just installing it doesn't do anything.
  • I tried to supply it by doing import "babel-polyfill" in my test file, as well as providing it in the plugins section of my .babelrc with no change.
  • In what file did you import that?
  • I imported it into my actual test and that solved the issue.
  • Why didn't adding it globally in webpack config file entry solved it? importing it for each test isn't ideal
  • babel-polyfill is deprecated. Don't use it. Look here for what happened any why: babeljs.io/blog/2019/03/19/…. Follow @jero's solution.
  • yes that totally fixed this.
  • in this case, if you're only introducing it to jest configs, shouldn't regenerator-runtime package be a dev dependency instead?
  • Yes @Periback, in the case you are using regenerator-runtime only for testing, you should include it as a dev dependencie. $ yarn add regenerator-runtime --dev
  • @rafafan2010 could you accept this as the answer? It's a much better answer in 2020. Doesn't involve adding another dependency. Has been supported since node 10, so no need for Babel.
  • This didn't solve my issue: only installing @babel/plugin-transform-runtime and configuring it as a plugin with "plugins": ["@babel/plugin-transform-runtime"] did solve the issue.
  • This solved my issue, also without adding the regenerator: true option. Setting "plugins": ["@babel/plugin-transform-runtime"] was enough
  • thanks, worked great!