使用带babel 6的async / await时获取意外的令牌
boot.js
require("babel-core/register")({
ignore: "./node_modules"
});
require("babel-polyfill");
asyncAwaitSample.js
async function() {
await someAsyncAction();
}()
.babelrc
{
"presets": ["es2015", "stage-0", "react"]
}
编译器在字符串async function() {
上出现错误,它说“意外令牌”{'“
答案 0 :(得分:2)
你安装了babel-plugin-transform-async-to-generator
吗?
npm install babel-plugin-transform-async-to-generator
并在.babelrc
{
"plugins": ["transform-async-to-generator"]
}
来源https://babeljs.io/docs/plugins/transform-async-to-generator/
然后执行:
(async function() {
await someAsyncAction();
})()