Configure ember-cli version >= 3 to use native async/await and generators

How to configure ember-cli version >= 3 to use native async/await and generators without babel regenerator polyfill and async/await transpiling

If you change your config/targets.js to only include browsers with native async/await, it should do what you want.

The default ember-cli@3+ blueprint already allows for native async/await without transpilation while in develoment (see config/targets.js of a ember new my-app output for ember-cli@3.1.0).

I also wrote a blog post about async/await configuration a little while back (back when configuration was not automatically setup for a new app by default) that you might find interesting: An async / await Configuration Adventure.

1 Like

In order to better debug asynchrony in tests I have an environment flag in my config/targets.js that looks something like this:

let browsers = [
  '> 5%',
  'ie 11',
  'last 2 Edge versions',
  'last 2 Chrome versions',
  'last 2 Firefox versions',
  'last 2 Safari versions'
];

if (process.env.EMBER_TARGET_CHROME) {
  browsers = ['last 1 Chrome versions'];
}

module.exports = {
  browsers
};

Which allows me to set the flag EMBER_TARGET_CHROME which uses only latest Chrome (which has async/await natively).

Since my CI does not set this flag Iā€™m still safe in the knowledge that the browsers I support are handled correctly. But I gain the advantage of seeing actual async/await in my test suite which is considerably easier to reason about.

I have a few aliases setup to automatically set that flag when I run commands (for example alias ets=EMBER_TARGET_CHROME=true ember test --serve).

Hope it helps!

3 Likes