2

I have a es2017 code with async/await, I want to transform it to es5 so that it'll be supported by most Node.js versions.

My current .babelrc file looks like this:

{
    "presets": ["es2015", "es2016", "es2017"]
}

So I'm transforming es2017 to es2016, from es2016 to es2015 and from es2015 to es5.

When I'm trying to run the code after I built it with babel src -d dist -s I'm getting error saying that: ReferenceError: regeneratorRuntime is not defined

How can I transform the es2017 code to es5? I wanna publish the code later and make it usable by node.js v4 and up.

Felix Kling
  • 795,719
  • 175
  • 1,089
  • 1,143
xerq
  • 2,362
  • 1
  • 9
  • 16
  • 1
    You did the transformation just fine, you only need to add to the babel polyfill – Bergi Jun 07 '17 at 12:48
  • @Bergi how do I use babel-polyfill if I'm building with babel-cli? I couldn't find that information anywhere – xerq Jun 07 '17 at 12:55
  • 1
    Related: [Transpile Async Await proposal with Babel.js?](https://stackoverflow.com/questions/28708975/transpile-async-await-proposal-with-babel-js/28709165). – Felix Kling Jun 07 '17 at 13:22

1 Answers1

5

Thanks to @Bergi I found a way how to solve this ReferenceError: regeneratorRuntime is not defined error.

I added the transform-runtime plugin to my .babelrc

Now my .babelrc is:

{
    "presets": ["es2015", "es2016", "es2017"],
    "plugins": ["transform-runtime"]
}

There aren't any errors now and it works fine.

xerq
  • 2,362
  • 1
  • 9
  • 16