ruby-on-rails-3amazon-elastic-beanstalksprocketsruby-2.0stack-level

Stack level too deep when compiling javascript files on ElasticBeanstalk Ruby2.0 on Rails3


I'm trying to migrate our Rails3 app from old ElasticBeanstalk environment running Ruby 1.9.3 to new one running Ruby 2.0.

Everything seems to work fine except "stack level too deep" error on assets precompile javascript files (css compiling worked well). It's working fine on my laptop with the same Gems installed. Below is the stack trace, any suggestion would be helpful. Thanks in advance.

    [webapp@ip-10-126-10-155 current]$ rake assets:precompile --trace
    ** Invoke assets:precompile (first_time)
    ** Execute assets:precompile
    /usr/bin/ruby2.0 /usr/local/bin/rake assets:precompile:all RAILS_ENV=staging RAILS_GROUPS=assets --trace
    ** Invoke assets:precompile:all (first_time)
    ** Execute assets:precompile:all
    ** Invoke assets:precompile:primary (first_time)
    ** Invoke assets:environment (first_time)
    ** Execute assets:environment
    ** Invoke environment (first_time)
    ** Execute environment
    ** Invoke tmp:cache:clear (first_time)
    ** Execute tmp:cache:clear
    ** Execute assets:precompile:primary
    rake aborted!
    SystemStackError: stack level too deep
      (in /var/app/current/app/assets/javascripts/all.js)
    /usr/local/share/ruby/gems/2.0/gems/rake-10.3.1/lib/rake/task.rb:183
    Tasks: TOP => assets:precompile:primary
    rake aborted!
    Command failed with status (1): [/usr/bin/ruby2.0 /usr/local/bin/rake asset...]
    /usr/local/share/ruby/gems/2.0/gems/rake-10.3.1/lib/rake/file_utils.rb:54:in `block in create_shell_runner'
    /usr/local/share/ruby/gems/2.0/gems/rake-10.3.1/lib/rake/file_utils.rb:45:in `call'
    /usr/local/share/ruby/gems/2.0/gems/rake-10.3.1/lib/rake/file_utils.rb:45:in `sh'
    /usr/local/share/ruby/gems/2.0/gems/rake-10.3.1/lib/rake/file_utils_ext.rb:37:in `sh'
    /usr/local/share/ruby/gems/2.0/gems/rake-10.3.1/lib/rake/file_utils.rb:82:in `ruby'
    /usr/local/share/ruby/gems/2.0/gems/rake-10.3.1/lib/rake/file_utils_ext.rb:37:in `ruby'
    /usr/local/share/ruby/gems/2.0/gems/actionpack-3.2.13/lib/sprockets/assets.rake:12:in `ruby_rake_task'
    /usr/local/share/ruby/gems/2.0/gems/actionpack-3.2.13/lib/sprockets/assets.rake:21:in `invoke_or_reboot_rake_task'
    /usr/local/share/ruby/gems/2.0/gems/actionpack-3.2.13/lib/sprockets/assets.rake:29:in `block (2 levels) in <top (required)>'
    /usr/local/share/ruby/gems/2.0/gems/rake-10.3.1/lib/rake/task.rb:240:in `call'
    /usr/local/share/ruby/gems/2.0/gems/rake-10.3.1/lib/rake/task.rb:240:in `block in execute'
    /usr/local/share/ruby/gems/2.0/gems/rake-10.3.1/lib/rake/task.rb:235:in `each'
    /usr/local/share/ruby/gems/2.0/gems/rake-10.3.1/lib/rake/task.rb:235:in `execute'
    /usr/local/share/ruby/gems/2.0/gems/rake-10.3.1/lib/rake/task.rb:179:in `block in invoke_with_call_chain'
    /usr/share/ruby/2.0/monitor.rb:211:in `mon_synchronize'
    /usr/local/share/ruby/gems/2.0/gems/rake-10.3.1/lib/rake/task.rb:172:in `invoke_with_call_chain'
    /usr/local/share/ruby/gems/2.0/gems/rake-10.3.1/lib/rake/task.rb:165:in `invoke'
    /usr/local/share/ruby/gems/2.0/gems/rake-10.3.1/lib/rake/application.rb:150:in `invoke_task'
    /usr/local/share/ruby/gems/2.0/gems/rake-10.3.1/lib/rake/application.rb:106:in `block (2 levels) in top_level'
    /usr/local/share/ruby/gems/2.0/gems/rake-10.3.1/lib/rake/application.rb:106:in `each'
    /usr/local/share/ruby/gems/2.0/gems/rake-10.3.1/lib/rake/application.rb:106:in `block in top_level'
    /usr/local/share/ruby/gems/2.0/gems/rake-10.3.1/lib/rake/application.rb:115:in `run_with_threads'
    /usr/local/share/ruby/gems/2.0/gems/rake-10.3.1/lib/rake/application.rb:100:in `top_level'
    /usr/local/share/ruby/gems/2.0/gems/rake-10.3.1/lib/rake/application.rb:78:in `block in run'
    /usr/local/share/ruby/gems/2.0/gems/rake-10.3.1/lib/rake/application.rb:176:in `standard_exception_handling'
    /usr/local/share/ruby/gems/2.0/gems/rake-10.3.1/lib/rake/application.rb:75:in `run'
    /usr/local/share/ruby/gems/2.0/gems/rake-10.3.1/bin/rake:33:in `<top (required)>'
    /usr/local/bin/rake:23:in `load'
    /usr/local/bin/rake:23:in `<main>'
    Tasks: TOP => assets:precompile

Solution

  • I've finally found the reason. That's because of these lines of code which was for supporting Emoji.

    module ActiveSupport
      module JSON
        module Encoding
          class << self
            def escape_with_json_gem(string)
              ::JSON.generate([string])[1..-2]
            end
            alias_method_chain :escape, :json_gem
          end 
        end 
      end 
    end