使用 async/await 时未定义 regeneratorRuntime

San*_*ord 2 javascript babeljs

我得到一个

“regeneratorRuntime 未定义”

尝试在项目中使用async/await时。

我的babelrc文件目前是这样的:

{
    "presets": ["env", "react"],
    "plugins": [
        "transform-runtime",
        "transform-object-rest-spread"
    ]
}
Run Code Online (Sandbox Code Playgroud)

我的package.json是:

{
    "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"
    }
}
Run Code Online (Sandbox Code Playgroud)

我对配置 babel 有点陌生,所以不确定在这里做什么。

Mar*_*awk 6

我使用以下帖子修复了类似的问题

在 .babelrc 中尝试以下操作:

{
  "presets": ["@babel/preset-env"],
  "plugins": [
    "@babel/plugin-transform-runtime"
    ], 
...
Run Code Online (Sandbox Code Playgroud)

具有以下开发依赖项: @babel/plugin-transform-runtime @babel/runtime