Babel CLI ReferenceError : regeneratorRuntime is not defined

Viewed 1544

These are my dependencies in package.json :

"devDependencies": {
  "babel-cli": "^6.24.1",
  "babel-polyfill": "^6.23.0",
  "babel-preset-env": "^1.6.0",
  "babel-preset-stage-0": "^6.5.0",
}

I can compile just fine with "babel server -d transpiled" (I have everything in a server folder instead of src).

The problem occurs when I try to run the transpiled code with "node transpiled/index.js". I get

ReferenceError: regeneratorRuntime is not defined

I did some searching and it seemed that the issue was that I don't have babel-polyfill when using await/async, but I actually do.

Here is my index.js file

require('babel-polyfill');
require('./server');

Here is also my .babelrc file

{
  "presets": ["env", "stage-0"]
}

What exactly is going on and why am I getting this error? I already have babel-polyfill so this shouldn't be happening.

2 Answers

I had the exact same problem and have been crying over it, my set up ended having all of these:

.babelrc

{ "presets": [ "env", "stage-2", "react" ] }

To avoid hoisting this is my app.js

require('babel-register');
require('babel-polyfill');
require('./server');

Where server is where my express code actually resides.

The pièce de résistance and what finally made my set up work without that damn error, in my webpack, for the entry point, I had to add babel-polyfill first.

const webpackConfig = {
    mode: 'development',
    entry: {
        app: ['babel-polyfill', APP_ENTRY_FILE]
    },
....

I hope it helps you!

Related