我得到一个
"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/