Babel-loader: How could I use async/await in browser with babel6?

Created on 18 Nov 2015  路  11Comments  路  Source: babel/babel-loader

babel-core 6.1.21
babel-loader 6.2.0

    module: {
      loaders: [{
        test: /\.js$/,
        exclude: /node_modules/,
        loader: 'babel',
        query: {
          plugins: ['transform-runtime'],
          presets: ['es2015', 'stage-0', 'stage-3']
        }
      }]
    }

have an error:

Uncaught TypeError: (0 , _typeof3.default) is not a function
question resolution in issue

Most helpful comment

@liam4 @jtHwong hi guys, in order to use async/await functions with webpack and babel you need to add a babel polyfill in your entry on webpack config, this work on both, nodejs and browser, take a look:

    entry:  ['babel-polyfill', path_to_entry],

    module: {

        loaders: [
            {
                test: /\.js$/,
                loader: 'babel',
                query: {
                    presets: ['es2015', 'stage-0'],
                    plugins: ['transform-runtime']
                }
            },
        ]
    }

this is how is working for me.

All 11 comments

Seeing the same issue: https://travis-ci.org/ipfs/js-ipfs-api/jobs/92021174#L1703

Update Not using generators though, the code runs fine in node@4 so only features from there are used

@Dignifiedquire Thanks.
My Node.js version is 0.12.7. If I update to 4.x, can I use async/await in browser ? (I can use async/await in Node.js now, but can't use in browser. )

@osomdevrepos I don't think that will work for running in a web browser - it looks like the code there is node.js.

There is the same issue in my application. How to solve it in browser? Thank you.

@liam4 @jtHwong hi guys, in order to use async/await functions with webpack and babel you need to add a babel polyfill in your entry on webpack config, this work on both, nodejs and browser, take a look:

    entry:  ['babel-polyfill', path_to_entry],

    module: {

        loaders: [
            {
                test: /\.js$/,
                loader: 'babel',
                query: {
                    presets: ['es2015', 'stage-0'],
                    plugins: ['transform-runtime']
                }
            },
        ]
    }

this is how is working for me.

Thank you, @jesus-repos.
My config is the same as yours. But the problem was still.
I updated my packages by npm update . So all of my packages were newest. Can you show your package.json?

I try Babel5 and everything is ok.

thanks @jesus-repos, worked here!

Resolving as a resolution to the original issue exists

solution

https://esausilva.com/2017/07/11/uncaught-referenceerror-regeneratorruntime-is-not-defined-two-solutions/

https://babeljs.io/docs/usage/polyfill/

OR

https://babeljs.io/docs/plugins/transform-regenerator/


OK

.babelrc


{
    "presets": ["env"]
}

webpack


require("babel-polyfill");

entry: ["babel-polyfill", "./src/backend-system/select-tree"],

image

Was this page helpful?
0 / 5 - 0 ratings