Using async/await with babel - require(“babel-polyfill”) line not at the top in built file

后端 未结 3 1774
予麋鹿
予麋鹿 2021-01-18 11:43

I am trying to use ES2017 async/await syntax with Babel. In package.json, I have

\"babel\": {
    \"plugins\": [
      \"babel-plugin-transform         


        
3条回答
  •  爱一瞬间的悲伤
    2021-01-18 12:36

    Since functions defined such as

    async function foo() {
        return 10;
    }
    

    can be used before they're defined in javascript, Babel is moving it to the top of the file during transpilation.

    To work around this, this try adjusting your syntax if possible:

    const foo = async function() {
        return 10;
    }
    

自定义标题
段落格式
字体
字号
代码语言
提交回复
热议问题