7

I am using async/await code and I'm receiving a "regeneratorRuntime is not defined error". I have tried several solutions from stack overflow, but I can't get any of them to work. Here's my configuration:

webpack.config.js:

module.exports = {    
    entry: ['babel-polyfill', './client/libs/compileTemplate/entry.jsx', './client/libs/compileTemplate/loginEntry.jsx'],
    output: {
        path: '/dist',
        publicPath: '/assets',
        filename: '[name].js'
    },
    plugins: plugins,
    externals: {},
    module: {
        loaders: require('./webpack.config.loaders')
    },

...

webpack.config.loaders.js:

module.exports = [
  {
    test: /\.jsx$/,
    loader: 'babel',
    query: {
      presets: ['es2015', 'stage-0', 'react'],
    }
  },
];

package.json: "devDependencies": { "babel-core": "^6.7.5", "babel-loader": "^6.2.4", "babel-polyfill": "^6.26.0", "babel-preset-es2015": "6.16.0", "babel-preset-react": "6.16.0", "babel-preset-stage-0": "^6.24.1", "json-loader": "^0.5.4", "less-loader": "2.2.3" }

I have also require("babel-core/register") at the top of my entry.jsx file.

Please let me know where I'm going wrong.

2 Answers 2

4

Okay, so several things resolved my problem.

1) npm i -S babel-preset-env babel-polyfill and in my webpack.config.js I added 'env', which takes care of es2015, es2016, and es2017 in one fell swoop:

module: {
    loaders: [
       { test: /\.jsx$/, loader: 'babel-loader', query: { presets: ['env', 'react'] } },
    ]
},


entry: [ './client/libs/compileTemplate/entry.jsx', './client/libs/compileTemplate/loginEntry.jsx'],

2) in my entry.jsx I had:

async function createSessionInfo() { // stuff here };

which was being hoisted above my require('babel-polyfill') statement in webpack, so I changed it to:

require('babel-polyfill');
const createSessionInfo = async function() {

And voila, problem gone. Oh, and make sure you have the latest babel-core and babel-loader.

Sign up to request clarification or add additional context in comments.

1 Comment

for me was just change the async function.. by const name = async function, thks
1

Async/await is not part of es2015 preset, you should either use es2017 or use transform-async-to-generator with es2015

3 Comments

I thought that's what stage-0 was doing?
added babel-preset-es2017 package to package.json and added es2017 to my presets, still not working. Any other ideas???
Oops I forgot to check for stage-0 in your code, yes I think stage-0 should allow you to use async/await. Maybe you should try to add "plugins": ["transform-async-generator-functions"] in your babel loader

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.