Posted over 1 year ago. Visible to the public. Repeats.

Using ES6 without a transpiler

If your app does not need to support IE11, you can use most ES6 features without a build step. Just deliver your plain JavaScript without transpilation through Babel or TypeScript, and modern browsers will run them natively.

Features supported by all modern browsers include:

  • fat arrow functions (() => { expr })
  • let / const
  • class
  • async / await
  • Promises
  • Generators
  • Symbols
  • Rest arguments (...args)
  • Destructuring

You won't be able to use import and export, or use npm modules.

See this ES6 compatibility matrix for details.

ES6 and Uglifier

You are probably going to run into an issue if you try to deploy a rails app which uses the assets pipeline (sprockets) and Uglifier to minify your JavaScript.

The asset "application.js" is not present in the asset pipeline. [...]

The error would be an ActionView::Template::Error with the message above, because rails fails at precompiling your ES6 javascripts.

You can check, if you ran into that issue by running bundle exec rails assets:precompile eiher on the server or in your development environment (don't forget to run bundle exec assets:clobber after you precompiled the assets on your local machine).

If the process fails due to an error similar to the one below, you can simply replace

config.assets.js_compressor = :uglifier


config.assets.js_compressor = true)

in config/environments/production.rb (and probably also config/environments/staging.rb) and you should be good.
:harmony => true simply enables the ES6 mode for Uglifier.

Uglifier::Error: Unexpected token operator «=», expected punc «,». To use ES6 syntax, harmony mode must be enabled with => true).

makandra has been working exclusively with Ruby on Rails since 2007. Our laser focus on a single technology has made us a leader in this space.

Owner of this card:

Henning Koch
Last edit:
4 months ago
by Henning Koch
About this deck:
We are makandra and do test-driven, agile Ruby on Rails software development.
License for source code
Posted by Henning Koch to makandra dev
This website uses short-lived cookies to improve usability.
Accept or learn more