我正在尝试转换async/await
语句以在浏览器中使用(早于IE11)。我使用的是Rollup和Babel 7,但是在实际运行代码时,Chrome总是出现错误。我觉得它与插件和/或它们的配置有关,但是已经停滞了。
这是我的.babelrc文件:
{
"presets": [
"@babel/preset-env"
],
"plugins": [
"@babel/plugin-proposal-class-properties",
"@babel/plugin-transform-async-to-generator",
"@babel/plugin-transform-runtime"
]
}
这里是我安装的软件包:
"devDependencies": {
"@babel/core": "^7.1.6",
"@babel/plugin-proposal-class-properties": "^7.1.0",
"@babel/plugin-transform-async-to-generator": "^7.1.0",
"@babel/plugin-transform-runtime": "^7.1.0",
"@babel/preset-env": "^7.1.6",
"babel-jest": "^21.2.0",
"concurrently": "^3.5.1",
"express": "^4.16.2",
"jest-cli": "^21.2.1",
"prettier": "^1.15.3",
"rollup": "^0.67.3",
"rollup-plugin-babel": "^4.0.3",
"rollup-plugin-uglify": "^3.0.0"
},
"dependencies": {
"@babel/runtime": "^7.1.5"
}
在浏览器中,我不断收到此错误:
Uncaught TypeError: Cannot read property 'mark' of undefined
...正在追溯到我的代码中如下所示的一行:
_regeneratorRuntime.mark(function _callee2() {
我不认为我需要导入Babel polyfill之类的东西,因为我已经阅读了有关如何实现所有内容的内容,但我可能是错的。任何方向将不胜感激。
答案 0 :(得分:-1)
根据这个答案https://stackoverflow.com/a/36821986/9816567,建议您在转换运行时插件上使用此配置
{
"plugins": [
["transform-runtime", {
"polyfill": false,
"regenerator": true
}]
]
}