ES6 + Uglifier with Jekyll: Uglifier::Error: Unexpected token: keyword (const)

1.2k Views Asked by At

Here is the complete error:

Liquid Exception: Unexpected token: keyword (const). To use ES6 syntax, harmony mode must be enabled with Uglifier.new(:harmony => true). in /_layouts/base.html

I found online that the solution should be to use:

Uglifier.compile(js, harmony: true)

in a production.rb file, which I don't have since I'm using Jekyll and all I can set is in config.yml:

...
assets:
  js_compressor: uglifier
...
2

There are 2 best solutions below

2
Andrew Koster On

Get rid of Uglifier. It doesn't support ES6, or at least it doesn't with the configuration that ships with Rails.

0
andi On

Try this one in your _config.yml: https://github.com/dart-lang/site-www/issues/502#issuecomment-365955221

  assets:
    ...
    external:
      uglifier:
        harmony: true