Posted 9 months 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 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).

Once an application no longer requires constant development, it needs periodic maintenance for stable and secure operation. makandra offers monthly maintenance contracts that let you focus on your business while we make sure the lights stay on.

Owner of this card:

Henning Koch
Last edit:
7 months ago
by Jakob Scholz
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 cookies to improve usability and analyze traffic.
Accept or learn more