Babel 6 regeneratorRuntime is not defined

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

    for future reference :

    As of Babel version 7.0.0-beta.55 stage presets have been removed

    refer blog https://babeljs.io/blog/2018/07/27/removing-babels-stage-presets

    async await can be still be used by

    https://babeljs.io/docs/en/babel-plugin-transform-async-to-generator#usage

    installation

    npm install --save-dev @babel/plugin-transform-async-to-generator
    

    usage in .babelrc

     { 
         "presets": ["@babel/preset-env"],
         "plugins": ["@babel/plugin-transform-async-to-generator"]
     }
    

    and using babel polyfill https://babeljs.io/docs/en/babel-polyfill

    installation

    npm install --save @babel/polyfill
    

    webpack.config.js

    module.exports = {
      entry: ["@babel/polyfill", "./app/js"],
    };
    

提交回复
热议问题