Babel 6 regeneratorRuntime is not defined

前端 未结 30 1852
暖寄归人
暖寄归人 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:21

    1 - Install babel-plugin-transform-async-to-module-method, babel-polyfil, bluebird , babel-preset-es2015, babel-core :

    npm install babel-plugin-transform-async-to-module-method babel-polyfill bluebird babel-preset-es2015 babel-core
    

    2 - Add in your js babel polyfill:

    import 'babel-polyfill';

    3 - Add plugin in your .babelrc:

    {
        "presets": ["es2015"],
        "plugins": [
          ["transform-async-to-module-method", {
            "module": "bluebird",
            "method": "coroutine"
          }]
        ]
    }
    

    Source : http://babeljs.io/docs/plugins/transform-async-to-module-method/

提交回复
热议问题