我正在尝试转换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这样的东西,因为我读过关于我如何实现所有东西的文章,但是我可能错了。任何方向都将不胜感激。
发布于 2018-11-30 22:30:15
从这个答案https://stackoverflow.com/a/36821986/9816567,它建议您在转换运行时插件上使用此配置。
{
"plugins": [
["transform-runtime", {
"polyfill": false,
"regenerator": true
}]
]
}https://stackoverflow.com/questions/53563982
复制相似问题