ES6 syntax, harmony mode must be enabled with Uglifier.new(:harmony => true

Ashish Jambhulkar picture Ashish Jambhulkar · May 9, 2019 · Viewed 10.2k times · Source

I am facing this problem

Uglifier::Error: Unexpected token: keyword (const). To use ES6 syntax, harmony mode must be enabled with Uglifier.new(:harmony => true). while deploying the project through capistrano on production.

I followed this solution

https://github.com/lautis/uglifier/issues/127#issuecomment-352224986

which suggests

replacing

config.assets.js_compressor = :uglifier

with

config.assets.js_compressor = Uglifier.new(harmony: true)

but even after doing that I am still facing the same error. I dont understand what went wrong. I am using uglifier (4.1.20) version

Answer

Sritam picture Sritam · Sep 15, 2019

Just leaving the answer here too:

In config/environments/production.rb replace

config.assets.js_compressor = :uglifier

with

config.assets.js_compressor = Uglifier.new(harmony: true)