xerq
xerq

Reputation: 2792

How to transform ES2017 to ES5

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.

Upvotes: 1

Views: 1696

Answers (1)

xerq
xerq

Reputation: 2792

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.

Upvotes: 4

Related Questions