javascript - 使用异步/等待时未定义 regeneratorRuntime

标签 javascript babeljs

我得到一个

"regeneratorRuntime is not defined"

当尝试在项目中使用 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 有点陌生,所以不确定在这里做什么。

最佳答案

我使用以下 post 解决了类似的问题

在 .babelrc 中尝试以下操作:

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

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

关于javascript - 使用异步/等待时未定义 regeneratorRuntime,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57541545/

相关文章:

javascript - 基于 req.user 验证用户是否是管理员是否安全?

javascript - Angular UI Typeahead - 防止下拉菜单在选择时关闭

javascript - 如何使用Jquery高亮svg map ?

node.js - 静态模式方法: Cannot read property 'myFindOrCreate' of undefined

react-native - 语法错误 : Unexpected identifier jest & babel 7 & react-native 0. 56

javascript - 使用插件在Wordpress中添加自定义CSS

javascript - 学习Javascript,为什么这两个函数表现不同?

node.js - Babel 不会忽略 node_modules 目录,尽管它在 "ignore"配置中

javascript - babel 中的 boolean 交换不起作用

javascript - Babili 缩小但不转译