Getting ExecJS when compiling rassets:precompile against production

437 views Asked by At

So I am running into an odd issue. I cannot precompile assets on Rails 5 against production. I keep getting the same error message, irrespective if I precompile on the server itself or on my local environment.

georg$ RAILS_ENV=production bundle exec rake assets:precompile
rake aborted!
ExecJS::RuntimeError: SyntaxError: Unexpected token: name ($)
get@(execjs):3538:630
(execjs):4058:47
(execjs):1:46
global code@(execjs):1:58
/Users/georg/.rvm/gems/ruby-2.2.4/gems/execjs-2.7.0/lib/execjs/external_runtime.rb:39:in `exec'
/Users/georg/.rvm/gems/ruby-2.2.4/gems/execjs-2.7.0/lib/execjs/external_runtime.rb:21:in `eval'
/Users/georg/.rvm/gems/ruby-2.2.4/gems/execjs-2.7.0/lib/execjs/external_runtime.rb:46:in `call'
/Users/georg/.rvm/gems/ruby-2.2.4/gems/uglifier-3.2.0/lib/uglifier.rb:195:in `run_uglifyjs'
/Users/georg/.rvm/gems/ruby-2.2.4/gems/uglifier-3.2.0/lib/uglifier.rb:157:in `compile'
/Users/georg/.rvm/gems/ruby-2.2.4/gems/sprockets-3.7.1/lib/sprockets/uglifier_compressor.rb:53:in `call'
/Users/georg/.rvm/gems/ruby-2.2.4/gems/sprockets-3.7.1/lib/sprockets/uglifier_compressor.rb:28:in `call'
/Users/georg/.rvm/gems/ruby-2.2.4/gems/sprockets-3.7.1/lib/sprockets/processor_utils.rb:75:in `call_processor'
/Users/georg/.rvm/gems/ruby-2.2.4/gems/sprockets-3.7.1/lib/sprockets/processor_utils.rb:57:in `block in call_processors'
/Users/georg/.rvm/gems/ruby-2.2.4/gems/sprockets-3.7.1/lib/sprockets/processor_utils.rb:56:in `reverse_each'
/Users/georg/.rvm/gems/ruby-2.2.4/gems/sprockets-3.7.1/lib/sprockets/processor_utils.rb:56:in `call_processors'
/Users/georg/.rvm/gems/ruby-2.2.4/gems/sprockets-3.7.1/lib/sprockets/loader.rb:134:in `load_from_unloaded'
/Users/georg/.rvm/gems/ruby-2.2.4/gems/sprockets-3.7.1/lib/sprockets/loader.rb:60:in `block in load'
/Users/georg/.rvm/gems/ruby-2.2.4/gems/sprockets-3.7.1/lib/sprockets/loader.rb:317:in `fetch_asset_from_dependency_cache'
/Users/georg/.rvm/gems/ruby-2.2.4/gems/sprockets-3.7.1/lib/sprockets/loader.rb:44:in `load'
/Users/georg/.rvm/gems/ruby-2.2.4/gems/sprockets-3.7.1/lib/sprockets/cached_environment.rb:20:in `block in initialize'
/Users/georg/.rvm/gems/ruby-2.2.4/gems/sprockets-3.7.1/lib/sprockets/cached_environment.rb:47:in `yield'
/Users/georg/.rvm/gems/ruby-2.2.4/gems/sprockets-3.7.1/lib/sprockets/cached_environment.rb:47:in `load'
/Users/georg/.rvm/gems/ruby-2.2.4/gems/sprockets-3.7.1/lib/sprockets/base.rb:66:in `find_asset'
/Users/georg/.rvm/gems/ruby-2.2.4/gems/sprockets-3.7.1/lib/sprockets/base.rb:73:in `find_all_linked_assets'
/Users/georg/.rvm/gems/ruby-2.2.4/gems/sprockets-3.7.1/lib/sprockets/manifest.rb:142:in `block in find'
/Users/georg/.rvm/gems/ruby-2.2.4/gems/sprockets-3.7.1/lib/sprockets/legacy.rb:114:in `block (2 levels) in logical_paths'
/Users/georg/.rvm/gems/ruby-2.2.4/gems/sprockets-3.7.1/lib/sprockets/path_utils.rb:228:in `block in stat_tree'
/Users/georg/.rvm/gems/ruby-2.2.4/gems/sprockets-3.7.1/lib/sprockets/path_utils.rb:212:in `block in stat_directory'
/Users/georg/.rvm/gems/ruby-2.2.4/gems/sprockets-3.7.1/lib/sprockets/path_utils.rb:209:in `each'
/Users/georg/.rvm/gems/ruby-2.2.4/gems/sprockets-3.7.1/lib/sprockets/path_utils.rb:209:in `stat_directory'
/Users/georg/.rvm/gems/ruby-2.2.4/gems/sprockets-3.7.1/lib/sprockets/path_utils.rb:227:in `stat_tree'
/Users/georg/.rvm/gems/ruby-2.2.4/gems/sprockets-3.7.1/lib/sprockets/path_utils.rb:231:in `block in stat_tree'
/Users/georg/.rvm/gems/ruby-2.2.4/gems/sprockets-3.7.1/lib/sprockets/path_utils.rb:212:in `block in stat_directory'
/Users/georg/.rvm/gems/ruby-2.2.4/gems/sprockets-3.7.1/lib/sprockets/path_utils.rb:209:in `each'
/Users/georg/.rvm/gems/ruby-2.2.4/gems/sprockets-3.7.1/lib/sprockets/path_utils.rb:209:in `stat_directory'
/Users/georg/.rvm/gems/ruby-2.2.4/gems/sprockets-3.7.1/lib/sprockets/path_utils.rb:227:in `stat_tree'
/Users/georg/.rvm/gems/ruby-2.2.4/gems/sprockets-3.7.1/lib/sprockets/path_utils.rb:231:in `block in stat_tree'
/Users/georg/.rvm/gems/ruby-2.2.4/gems/sprockets-3.7.1/lib/sprockets/path_utils.rb:212:in `block in stat_directory'
/Users/georg/.rvm/gems/ruby-2.2.4/gems/sprockets-3.7.1/lib/sprockets/path_utils.rb:209:in `each'
/Users/georg/.rvm/gems/ruby-2.2.4/gems/sprockets-3.7.1/lib/sprockets/path_utils.rb:209:in `stat_directory'
/Users/georg/.rvm/gems/ruby-2.2.4/gems/sprockets-3.7.1/lib/sprockets/path_utils.rb:227:in `stat_tree'
/Users/georg/.rvm/gems/ruby-2.2.4/gems/sprockets-3.7.1/lib/sprockets/path_utils.rb:231:in `block in stat_tree'
/Users/georg/.rvm/gems/ruby-2.2.4/gems/sprockets-3.7.1/lib/sprockets/path_utils.rb:212:in `block in stat_directory'
/Users/georg/.rvm/gems/ruby-2.2.4/gems/sprockets-3.7.1/lib/sprockets/path_utils.rb:209:in `each'
/Users/georg/.rvm/gems/ruby-2.2.4/gems/sprockets-3.7.1/lib/sprockets/path_utils.rb:209:in `stat_directory'
/Users/georg/.rvm/gems/ruby-2.2.4/gems/sprockets-3.7.1/lib/sprockets/path_utils.rb:227:in `stat_tree'
/Users/georg/.rvm/gems/ruby-2.2.4/gems/sprockets-3.7.1/lib/sprockets/legacy.rb:105:in `each'
/Users/georg/.rvm/gems/ruby-2.2.4/gems/sprockets-3.7.1/lib/sprockets/legacy.rb:105:in `block in logical_paths'
/Users/georg/.rvm/gems/ruby-2.2.4/gems/sprockets-3.7.1/lib/sprockets/legacy.rb:104:in `each'
/Users/georg/.rvm/gems/ruby-2.2.4/gems/sprockets-3.7.1/lib/sprockets/legacy.rb:104:in `logical_paths'
/Users/georg/.rvm/gems/ruby-2.2.4/gems/sprockets-3.7.1/lib/sprockets/manifest.rb:140:in `find'
/Users/georg/.rvm/gems/ruby-2.2.4/gems/sprockets-3.7.1/lib/sprockets/manifest.rb:185:in `compile'
/Users/georg/.rvm/gems/ruby-2.2.4/gems/sprockets-rails-3.2.0/lib/sprockets/rails/task.rb:68:in `block (3 levels) in define'
/Users/georg/.rvm/gems/ruby-2.2.4/gems/sprockets-3.7.1/lib/rake/sprocketstask.rb:147:in `with_logger'
/Users/georg/.rvm/gems/ruby-2.2.4/gems/sprockets-rails-3.2.0/lib/sprockets/rails/task.rb:67:in `block (2 levels) in define'
/Users/georg/.rvm/gems/ruby-2.2.4/gems/rake-12.0.0/exe/rake:27:in `<top (required)>'
/Users/georg/.rvm/gems/ruby-2.2.4/bin/ruby_executable_hooks:15:in `eval'
/Users/georg/.rvm/gems/ruby-2.2.4/bin/ruby_executable_hooks:15:in `<main>'
Tasks: TOP => assets:precompile
(See full trace by running task with --trace)

To solve the issue I did the following:

1.) I have a subfolder structure I am referring to under assets/javascript, so I added that to the asset path and I thought that may be the issue - but apparently it isn't. I read the paths in like this:

Dir.glob("#{Rails.root}/app/assets/javascripts/**/").each do |path|
  config.assets.paths << path
end

2.) I removed all references from application.js - it is empty and I still get the error.

3.) I removed / added therubyracer

# gem 'therubyracer', platforms: :ruby

4.) I installed and updated the execjs gem independently

5.) Eventually, I was running out of ideas. Given that I get the error when there's nothing to compile.

My environment:

georg$ rails -v
Rails 5.0.5
georg$ ruby -v
ruby 2.2.4p230 (2015-12-16 revision 53155) [x86_64-darwin16]

The compiling was done on OSx and Debian.

Any hints are much appreciated!!

1

There are 1 answers

0
Georg Keferböck On

The issue was with a custom js file in the tree. Given that there are plenty of js files included in the applciation.js it is obviously a painful way of trial and error to get to the bottom of the issue given the limited information I got from the trace. It would be interesting to know if there are ways to get more information in return to avoid lengthy inefficient debug sessions.

For the time being, I removed all js, added them one-by-one and run a precompile till I hit the offending code.