Uglifier : Push fail on Heroku - Rails 5.2.3

913 Views Asked by At

I'm trying to deploy my app without database on Heroku and I got this error with Uglifier:

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

/tmp/build_03ed840249175186eece9eb6563a8337/app/assets/config/manifest.js:2

/tmp/build_03ed840249175186eece9eb6563a8337/vendor/bundle/ruby/2.5.0/gems/uglifier-4.1.20/lib/uglifier.rb:234:in `parse_result'

As it is advised, I replaced in production.rb

config.assets.js_compressor = :uglifier

with

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

But then, I have this issue when pushing it:

rake aborted!
Uglifier::Error: Unexpected character '#'     

/tmp/build_c9603da773e8afa6c70b30bb536a85ab/vendor/bundle/ruby/2.5.0/gems/uglifier-4.1.20/lib/uglifier.rb:234:in `parse_result'       

/tmp/build_c9603da773e8afa6c70b30bb536a85ab/vendor/bundle/ruby/2.5.0/gems/uglifier-4.1.20/lib/uglifier.rb:216:in `run_uglifyjs' 

After some searches, the advice seems to do exactly the same things that I did in production.rb...

When I ran

RAILS_ENV=production rake assets:precompile --trace

I don't have any error !

Here is my Gemfile:

source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }

ruby '2.5.1'

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 5.2.2'
# Use pg/don't use it
#gem 'pg'
# Use Puma as the app server
gem 'puma', '~> 3.11'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 4.1.20'
# See https://github.com/rails/execjs#readme for more supported runtimes
# gem 'mini_racer', platforms: :ruby

# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.2'
# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
gem 'turbolinks', '~> 5'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.5'
# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 4.0'
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'

# Use ActiveStorage variant
# gem 'mini_magick', '~> 4.8'

# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development

# Reduces boot times through caching; required in config/boot.rb
gem 'bootsnap', '>= 1.1.0', require: false

group :development, :test do
  # Call 'byebug' anywhere in the code to stop execution and get a debugger console
  gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
end

group :development do
  # Access an interactive console on exception pages or by calling 'console' anywhere in the code.
  gem 'web-console', '>= 3.3.0'
  gem 'listen', '>= 3.0.5', '< 3.2'
  # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
  gem 'spring'
  gem 'spring-watcher-listen', '~> 2.0.0'
end

group :test do
  # Adds support for Capybara system testing and selenium driver
  gem 'capybara', '>= 2.15'
  gem 'selenium-webdriver'
  # Easy installation and use of chromedriver to run system tests with Chrome
  gem 'chromedriver-helper'
end

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]

#Style
gem 'bootstrap', '~> 4.3.1'
gem 'jquery-rails', '~> 4.3.3', '>= 4.3.3'
gem 'font-awesome-sass', '~> 5.8.1'

UPDATE

I started over with a new app, this one with a database. Pushed step by step, to see exactly where the error is. After adding my custom CSS, without any .js, I edited assets.rb with my usual:

Rails.application.config.assets.precompile += [/.*\.png/,/.*\.ico/,/.*\.jpg/,/.*\.js/,/.*\.scss/,/.*\.svg/]
Rails.application.config.assets.precompile << %w( *.scss *.js )
Rails.application.config.assets.paths << Rails.root.join("lib")
Rails.application.config.assets.paths << Rails.root.join("vendor")

And here come the error... Maybe my assets.rb is badly written ?

UPDATE 2

Tried to replace the Uglifier gem with Closure-compiler, got the following error:

rake aborted!
       Closure::Error: sh: 1: java: not found
       /tmp/build_e1adeef66970d059737b424179dfef90/app/assets/config/manifest.js:2
       /tmp/build_e1adeef66970d059737b424179dfef90/vendor/bundle/ruby/2.5.0/gems/closure-compiler-1.1.14/lib/closure/compiler.rb:68:in `compile_files'

Thank you for your answer

0

There are 0 best solutions below