【问题标题】:regeneratorRuntime is not defined when using async/await使用 async/await 时未定义 regeneratorRuntime
【发布时间】:2019-08-18 04:00:24
【问题描述】:

我得到了一个

“regeneratorRuntime 未定义”

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

我的babelrc 文件目前是这个:

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

而我的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"
    }
}

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

【问题讨论】:

  • stack question 对您有帮助吗?它包含 Babel 6 和 7 的答案。我认为您还在这里为 @babel/runtime 和 babel-plugin-transform-runtime 等混合了 babel 主要版本。
  • 找到答案here

标签: javascript babeljs


【解决方案1】:

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

在 .babelrc 中尝试以下操作:

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

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

【讨论】:

    【解决方案2】:

    我认为这是因为您使用的是@babel/runtime。

    我的设置是@babel/runtime、@babel/core、@babel/plugin-transform-runtime 和.bablerc 设置

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

    我希望这会有所帮助。

    【讨论】:

      猜你喜欢
      • 2019-12-15
      • 2018-04-11
      • 2016-10-29
      • 2018-03-05
      • 2018-11-27
      • 2021-10-05
      • 2017-06-09
      • 2017-07-13
      • 1970-01-01
      相关资源
      最近更新 更多