Rails 5 -> 6 Upgrade: ES6 Uglifier bug

During a recent Rails 5 -> 6 upgrade we encountered an ES6 bug. Here’s the error message:

1
ActionView::Template::Error (Unexpected token: keyword (const). To use ES6 syntax, harmony mode must be enabled with Uglifier.new(:harmony => true)

ES6 is the new standard, in Rails 6, and it doesn’t support Uglifier. However, it’s not a big problem because Webpacker is now the default Rails 6 asset compiler. Webpacker removes the need for Uglifier so we can safely remove it.

  1. Remove the uglifier gem
    1
    
    - gem 'uglifier'
    
  2. Remove the js_compressor step from development.rb and production.rb
1
- config.assets.js_compressor = :uglifier