Babel 6 regeneratorRuntime is not defined

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

    Besides polyfill, I use babel-plugin-transform-runtime. The plugin is described as:

    Externalize references to helpers and builtins, automatically polyfilling your code without polluting globals. What does this actually mean though? Basically, you can use built-ins such as Promise, Set, Symbol etc as well use all the Babel features that require a polyfill seamlessly, without global pollution, making it extremely suitable for libraries.

    It also includes support for async/await along with other built-ins of ES 6.

    $ npm install --save-dev babel-plugin-transform-runtime
    

    In .babelrc, add the runtime plugin

    {
      "plugins": [
        ["transform-runtime", {
          "regenerator": true
        }]
      ]
    }
    

    Note If you're using babel 7, the package has been renamed to @babel/plugin-transform-runtime.

提交回复
热议问题