Babel 6 regeneratorRuntime is not defined

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

    This error is caused when async/await functions are used without the proper Babel plugins. As of March 2020, the following should be all you need to do. (@babel/polyfill and a lot of the accepted solutions have been deprecated in Babel. Read more in the Babel docs.)

    In the command line, type:

    npm install --save-dev @babel/plugin-transform-runtime
    

    In your babel.config.js file, add this plugin @babel/plugin-transform-runtime. Note: The below example includes the other presets and plugins I have for a small React/Node/Express project I worked on recently:

    module.exports = {
      presets: ['@babel/preset-react', '@babel/preset-env'],
      plugins: ['@babel/plugin-proposal-class-properties', 
      '@babel/plugin-transform-runtime'],
    };
    

提交回复
热议问题