Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 379
Ashish Jambhulkar Avatar asked May 09 '19 15:05

Ashish Jambhulkar


3 Answers

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)
like image 152
Sritam Avatar answered Oct 18 '22 04:10

Sritam


On Rails 6.1, I managed to solve this issue by:

  1. Removing the uglifier gem from Gemfile.
  2. Removing the config.assets.js_compressor entry in config/environments/production.rb and config/environments/development.rb.

Ref.: https://www.mintbit.com/blog/rails-5-6-upgrade-es6-uglifier-bug

like image 3
Eduardo Sztokbant Avatar answered Oct 18 '22 03:10

Eduardo Sztokbant


Uglifier only works with ES5. If you need to compress ES6, ruby-terser is a better option.

like image 1
mamantoha Avatar answered Oct 18 '22 05:10

mamantoha