babel 6 async / await: Unexpected token

前端 未结 5 2021
眼角桃花
眼角桃花 2021-02-07 09:33

Im having trouble getting async / await transforms working. What am I missing?

My .babelrc:

{
  \"presets\": [ \"es2015\", \"stage-0\" ]
}
5条回答
  •  生来不讨喜
    2021-02-07 10:02

    According to this post you need to have babel-polyfill

    Babel 6 regeneratorRuntime is not defined with async/await

    Hopefully it'll help you :)

    EDIT:

    It doesn't have to be babel-polyfill but it's the only one I used.

    As Gothdo said: the await keyword has to be in a function scope. Moreover, this function definition has to have the async keyword.

    This means that you can not have the await keyword on the top-level scope.

提交回复
热议问题