Babel 6 regeneratorRuntime is not defined

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

    This solution is out of date.

    I found the solution in the youtube comments of this video https://www.youtube.com/watch?v=iWUR04B42Hc&lc=Ugyq8UJq-OyOzsKIIrB4AaABAg

    This should direct to the correct comment. Much props to "beth w" for finding the solution.

    Beth W 3 months ago (edited)
    Another change I had to make in 2019 - babel no longer uses the stage-0 preset as of v7 apparently, so at 26:15 instead of 'npm install --save-dev babel-polyfill babel-preset-stage-0', I had to do:

    npm install --save @babel/polyfill

    Which covers both of the older options. Then, in the entry point for the app I > included '@babel/polyfill', and in the query presets I left it as-is. So the webpack config ends up looking like:

    const path = require('path');
    module.exports = {
        entry: {
            app: ['@babel/polyfill', './src/app.js']
        },
        output: {
            path: path.resolve(__dirname, 'build'),
            filename: 'app.bundle.js'
        },
        mode: 'development',
        module: {
            rules: [{
                test: /\.js?$/,
                exclude: /node_modules/,
                loader: 'babel-loader',
                query: {
                    presets: ['@babel/preset-env']
                }
            }]
        }
    }
    

    Hope that helps someone!

提交回复
热议问题