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
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)
On Rails 6.1, I managed to solve this issue by:
uglifier
gem from Gemfile
.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
Uglifier only works with ES5. If you need to compress ES6, ruby-terser is a better option.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With