2

I am getting a

"regeneratorRuntime is not defined"

when trying to use async/await in a project.

My babelrc file is this currently:

{
    "presets": ["env", "react"],
    "plugins": [
        "transform-runtime",
        "transform-object-rest-spread"
    ]
}

and my package.json is:

{
    "name": "****",
    "version": "1.0.0",
    "description": "****",
    "main": "index.js",
    "author": "****",
    "license": "UNLICENSED",
    "private": true,
    "scripts": {
        "start": "yarn build && nodemon server/index.js --ignore dist/ --ignore public/",
        "watch": "parcel watch public/index.html --public-url /",
        "build": "parcel build public/index.html --public-url /",
        "test": "jest"
    },
    "dependencies": {
        "@babel/runtime": "^7.5.5",
        "axios": "^0.19.0",
        "express": "^4.17.1",
        "express-validator": "^6.1.1",
        "react": "^16.9.0",
        "react-dom": "^16.9.0",
        "super-reset-css": "^1.0.5"
    },
    "devDependencies": {
        "babel-core": "^6.26.3",
        "babel-plugin-transform-object-rest-spread": "^6.26.0",
        "babel-plugin-transform-runtime": "^6.23.0",
        "babel-preset-env": "^1.7.0",
        "babel-preset-react": "^6.24.1",
        "jest": "^24.8.0",
        "nodemon": "^1.14.11",
        "parcel-bundler": "^1.5.1",
        "sass": "^1.22.9"
    }
}

I'm sort of new to configuring babel so not sure what to do here.

ravibagul91
  • 20,072
  • 5
  • 36
  • 59
Sandra Willford
  • 3,459
  • 11
  • 49
  • 96
  • Does this [stack question](https://stackoverflow.com/questions/33527653/babel-6-regeneratorruntime-is-not-defined) help you out? It contains answers for Babel 6 and 7. I think you are also mixing babel major versions here for `@babel/runtime` and `babel-plugin-transform-runtime` etc. . – ford04 Aug 20 '19 at 09:14
  • Found the answer [here](https://stackoverflow.com/questions/50907975/babel-regeneratorruntime-is-not-defined-when-using-transform-async-to-generat) – MarshHawk Mar 02 '20 at 01:58

2 Answers2

8

I fixed a similar problem using the following post

Try the following in .babelrc:

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

with the following dev dependencies: @babel/plugin-transform-runtime @babel/runtime

MarshHawk
  • 491
  • 7
  • 13
1

I think it is because you are using @babel/runtime.

My set up is @babel/runtime, @babel/core, @babel/plugin-transform-runtime and in the .bablerc set

"plugins": ["@babel/transform-runtime"]

I hope this helps.

ravibagul91
  • 20,072
  • 5
  • 36
  • 59
Kevin
  • 1,271
  • 9
  • 14