Babel 6 regeneratorRuntime is not defined

前端 未结 30 1916
暖寄归人
暖寄归人 2020-11-22 03:49

I\'m trying to use async, await from scratch on Babel 6, but I\'m getting regeneratorRuntime is not defined.

.babelrc file

{
    \"presets\": [ \"es2         


        
30条回答
  •  自闭症患者
    2020-11-22 04:35

    As of Oct 2019 this worked for me:

    Add this to the preset.

     "presets": [
          "@babel/preset-env"
        ]
    

    Then install regenerator-runtime using npm.

    npm i regenerator-runtime
    

    And then in your main file use: (this import is used only once)

    import "regenerator-runtime/runtime";
    

    This is will enable you to use async awaits in your file and remove the regenerator error

提交回复
热议问题