Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

regeneratorRuntime is not defined when using async/await

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.

like image 724
Sandra Willford Avatar asked Sep 17 '26 17:09

Sandra Willford


2 Answers

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

like image 63
MarshHawk Avatar answered Sep 19 '26 07:09

MarshHawk


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.

like image 29
Kevin Avatar answered Sep 19 '26 06:09

Kevin