3

I am NOT trying to run embedded JavaScript within Ruby. I am trying to use the standard Rails Asset Pipeline supporting external JavaScript files. This rake asset:precompile is failing. The fix is mentioned in the answer referring to a patch to ExecJS runtimes.rb module. It does not require installation of TheRubyRacer.

rake assets:precompile RAILS_ENV=production --trace is failing

Environment: Ruby 2.0.0, Rails 4.0.3, Windows 8.1, PostreSQL 9.3.3, Devise 3.2.4, Rake 10.3.2, rspec-rails 3.0.1

My application seems to be working fine, as far as it goes. I am continuing to work on it, but decided to push it to Github and Heroku again before I make further changes. However, when I try to precompile my assets on my local system before I do that, it fails where it used to work fine. From the trace, it appears to me that it is failing in JavaScript, but I'm no expert in the precompile process. I eliminated my own JavaScript code and tried it, but it still fails. How can I fix this?

config/application.rb is:

require File.expand_path('../boot', __FILE__)

# Pick the frameworks you want:
require "active_record/railtie"
require "action_controller/railtie"
require "action_mailer/railtie"
require "sprockets/railtie"
# require "rails/test_unit/railtie"

# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(:default, Rails.env)

module kac_app
  class Application < Rails::Application

    # don't generate RSpec tests for views and helpers
    config.generators do |g|

      g.test_framework :rspec, fixture: true
      g.fixture_replacement :factory_girl, dir: 'spec/factories'


      g.view_specs false
      g.helper_specs false
    end

    # Settings in config/environments/* take precedence over those specified here.
    # Application configuration should go into files in config/initializers
    # -- all .rb files in that directory are automatically loaded.

    # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
    # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
    # config.time_zone = 'Central Time (US & Canada)'

    # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
    # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
    # config.i18n.default_locale = :de

    #  not needed at 4.0?
    config.assets.initialize_on_precompile = false

    #  Load files in lib
    config.autoload_paths += %W(#{config.root}/lib)

  end
end

The only file in assets/javascript/ is application.js and it is:

// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// compiled file.
//
// Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
// about supported directives.
//
//= require jquery
//= require jquery_ujs
//= require jquery.ui.all
//= require jquery.turbolinks
//= require turbolinks
//= require bootstrap
//= require dataTables/jquery.dataTables
//= require dataTables/jquery.dataTables.bootstrap3
//= require_tree .

For completeness in assets/stylesheets:

application.css.scss

/*
 * This is a manifest file that'll automatically include all the stylesheets available in this directory
 * and any sub-directories. You're free to add application-wide styles to this file and they'll appear at
 * the top of the compiled file, but it's generally better to create a new file per style scope.
 *= require_self
 *= require jquery.ui.core
 *= require jquery.ui.theme
 *= require dataTables/src/demo_table_jui
 *= require_tree .
*/

framework_and_overrides.css.scss

// from railscast 329

$navbarBackground: #555;
$navbarBackgroundHighlight: #888;
$navbarText: #eee;
$navbarLinkColor: #eee;


// import the CSS framework
@import "bootstrap";
body { padding-top: 20px; }

// make all images responsive by default
img {
  @extend .img-responsive;
  margin: 0 auto;
  }
// override for the 'Home' navigation link
.navbar-brand {
  font-size: inherit;
  }

// THESE ARE EXAMPLES YOU CAN MODIFY
// create your own classes
// to make views framework-neutral
.column {
  @extend .col-md-6;
  @extend .text-center;
  }
.form {
  @extend .col-md-6;
  }
.form-centered {
  @extend .col-md-6;
  @extend .text-center;
  }
.submit {
  @extend .btn;
  @extend .btn-primary;
  @extend .btn-lg;
  }
// apply styles to HTML elements
// to make views framework-neutral
main {
  @extend .container;
  background-color: #eee;
  padding-bottom: 80px;
  width: 100%;
  margin-top: 51px; // accommodate the navbar
  }
section {
  @extend .row;
  margin-top: 20px;
  }

// Styles for Devise views
// using Bootstrap
// generated by the rails_layout gem
.authform {
  padding-top: 30px;
  max-width: 320px;
  margin: 0 auto;
}
.authform form {
  @extend .well;
  @extend .well-lg;
  padding-bottom: 40px;
}
.authform .right {
  float: right !important;
}
.authform .button {
  @extend .btn;
  @extend .btn-primary;
}
.authform fieldset {
  @extend .well;
}
#error_explanation {
  @extend .alert;
  @extend .alert-danger;
}
#error_explanation h2 {
  font-size: 16px;
}
.button-xs {
  @extend .btn;
  @extend .btn-primary;
  @extend .btn-xs;
}

//  Tighten things up here...

.form-group {
  margin-bottom: 5px; // Was 15px
}

/* line 194, D:/BitNami/rubystack-2.0.0-11/ruby/lib/ruby/gems/2.0.0/gems/bootstrap-sass-3.1.1.0/vendor/assets/stylesheets/bootstrap/_forms.scss */
.radio,
.checkbox {
  margin-top: 5px;
  margin-bottom: 5px;
}

scaffolds.css.scss

body {
  background-color: #fff;
  color: #333;
  font-family: verdana, arial, helvetica, sans-serif;
  font-size: 13px;
  line-height: 18px;
}

p, ol, ul, td {
  font-family: verdana, arial, helvetica, sans-serif;
  font-size: 13px;
  line-height: 18px;
}

pre {
  background-color: #eee;
  padding: 10px;
  font-size: 11px;
}

a {
  color: #000;
  &:visited {
    color: #666;
  }
  &:hover {
    color: #fff;
    background-color: #000;
  }
}

div {
  &.field, &.actions {
    margin-bottom: 10px;
  }
}

#notice {
  color: green;
}

.field_with_errors {
  padding: 2px;
  background-color: red;
  display: table;
}

#error_explanation {
  width: 450px;
  border: 2px solid red;
  padding: 7px;
  padding-bottom: 0;
  margin-bottom: 20px;
  background-color: #f0f0f0;
  h2 {
    text-align: left;
    font-weight: bold;
    padding: 5px 5px 5px 15px;
    font-size: 12px;
    margin: -7px;
    margin-bottom: 0px;
    background-color: #c00;
    color: #fff;
  }
  ul li {
    font-size: 12px;
    list-style: square;
  }
}

The trace is:

D:\BitNami\rubystack-2.0.0-11\projects\kac_app>rake assets:precompile RAILS_ENV=production --trace
** Invoke assets:precompile (first_time)
** Invoke assets:environment (first_time)
** Execute assets:environment
** Invoke environment (first_time)
** Execute environment
** Execute assets:precompile
rake aborted!
ExecJS::RuntimeError:
  (in D:/BitNami/rubystack-2.0.0-11/projects/kac_app/app/assets/javascripts/application.js)
D:/BitNami/rubystack-2.0.0-11/ruby/lib/ruby/gems/2.0.0/gems/execjs-2.2.0/lib/execjs/external_runtime.rb:152:in `exec_run
time'
D:/BitNami/rubystack-2.0.0-11/ruby/lib/ruby/gems/2.0.0/gems/execjs-2.2.0/lib/execjs/external_runtime.rb:29:in `exec'
D:/BitNami/rubystack-2.0.0-11/ruby/lib/ruby/gems/2.0.0/gems/uglifier-2.5.0/lib/uglifier.rb:186:in `really_compile'
D:/BitNami/rubystack-2.0.0-11/ruby/lib/ruby/gems/2.0.0/gems/uglifier-2.5.0/lib/uglifier.rb:110:in `compile'
D:/BitNami/rubystack-2.0.0-11/ruby/lib/ruby/gems/2.0.0/gems/sprockets-2.11.0/lib/sprockets/uglifier_compressor.rb:25:in
`evaluate'
D:/BitNami/rubystack-2.0.0-11/ruby/lib/ruby/gems/2.0.0/gems/tilt-1.4.1/lib/tilt/template.rb:103:in `render'
D:/BitNami/rubystack-2.0.0-11/ruby/lib/ruby/gems/2.0.0/gems/sprockets-2.11.0/lib/sprockets/context.rb:197:in `block in e
valuate'
D:/BitNami/rubystack-2.0.0-11/ruby/lib/ruby/gems/2.0.0/gems/sprockets-2.11.0/lib/sprockets/context.rb:194:in `each'
D:/BitNami/rubystack-2.0.0-11/ruby/lib/ruby/gems/2.0.0/gems/sprockets-2.11.0/lib/sprockets/context.rb:194:in `evaluate'
D:/BitNami/rubystack-2.0.0-11/ruby/lib/ruby/gems/2.0.0/gems/sprockets-2.11.0/lib/sprockets/bundled_asset.rb:25:in `initi
alize'
D:/BitNami/rubystack-2.0.0-11/ruby/lib/ruby/gems/2.0.0/gems/sprockets-2.11.0/lib/sprockets/base.rb:377:in `new'
D:/BitNami/rubystack-2.0.0-11/ruby/lib/ruby/gems/2.0.0/gems/sprockets-2.11.0/lib/sprockets/base.rb:377:in `build_asset'
D:/BitNami/rubystack-2.0.0-11/ruby/lib/ruby/gems/2.0.0/gems/sprockets-2.11.0/lib/sprockets/index.rb:94:in `block in buil
d_asset'
D:/BitNami/rubystack-2.0.0-11/ruby/lib/ruby/gems/2.0.0/gems/sprockets-2.11.0/lib/sprockets/caching.rb:58:in `cache_asset
'
D:/BitNami/rubystack-2.0.0-11/ruby/lib/ruby/gems/2.0.0/gems/sprockets-2.11.0/lib/sprockets/index.rb:93:in `build_asset'
D:/BitNami/rubystack-2.0.0-11/ruby/lib/ruby/gems/2.0.0/gems/sprockets-2.11.0/lib/sprockets/base.rb:287:in `find_asset'
D:/BitNami/rubystack-2.0.0-11/ruby/lib/ruby/gems/2.0.0/gems/sprockets-2.11.0/lib/sprockets/index.rb:61:in `find_asset'
D:/BitNami/rubystack-2.0.0-11/ruby/lib/ruby/gems/2.0.0/gems/sprockets-2.11.0/lib/sprockets/manifest.rb:211:in `block in
find_asset'
D:/BitNami/rubystack-2.0.0-11/ruby/lib/ruby/gems/2.0.0/gems/sprockets-2.11.0/lib/sprockets/manifest.rb:257:in `benchmark
'
D:/BitNami/rubystack-2.0.0-11/ruby/lib/ruby/gems/2.0.0/gems/sprockets-2.11.0/lib/sprockets/manifest.rb:210:in `find_asse
t'
D:/BitNami/rubystack-2.0.0-11/ruby/lib/ruby/gems/2.0.0/gems/sprockets-2.11.0/lib/sprockets/manifest.rb:119:in `block in
compile'
D:/BitNami/rubystack-2.0.0-11/ruby/lib/ruby/gems/2.0.0/gems/sprockets-2.11.0/lib/sprockets/manifest.rb:118:in `each'
D:/BitNami/rubystack-2.0.0-11/ruby/lib/ruby/gems/2.0.0/gems/sprockets-2.11.0/lib/sprockets/manifest.rb:118:in `compile'
D:/BitNami/rubystack-2.0.0-11/ruby/lib/ruby/gems/2.0.0/gems/sprockets-rails-2.0.1/lib/sprockets/rails/task.rb:60:in `blo
ck (3 levels) in define'
D:/BitNami/rubystack-2.0.0-11/ruby/lib/ruby/gems/2.0.0/gems/sprockets-2.11.0/lib/rake/sprocketstask.rb:146:in `with_logg
er'
D:/BitNami/rubystack-2.0.0-11/ruby/lib/ruby/gems/2.0.0/gems/sprockets-rails-2.0.1/lib/sprockets/rails/task.rb:59:in `blo
ck (2 levels) in define'
D:/BitNami/rubystack-2.0.0-11/ruby/lib/ruby/gems/2.0.0/gems/rake-10.3.2/lib/rake/task.rb:240:in `call'
D:/BitNami/rubystack-2.0.0-11/ruby/lib/ruby/gems/2.0.0/gems/rake-10.3.2/lib/rake/task.rb:240:in `block in execute'
D:/BitNami/rubystack-2.0.0-11/ruby/lib/ruby/gems/2.0.0/gems/rake-10.3.2/lib/rake/task.rb:235:in `each'
D:/BitNami/rubystack-2.0.0-11/ruby/lib/ruby/gems/2.0.0/gems/rake-10.3.2/lib/rake/task.rb:235:in `execute'
D:/BitNami/rubystack-2.0.0-11/ruby/lib/ruby/gems/2.0.0/gems/rake-10.3.2/lib/rake/task.rb:179:in `block in invoke_with_ca
ll_chain'
D:/BitNami/rubystack-2.0.0-11/ruby/lib/ruby/2.0.0/monitor.rb:211:in `mon_synchronize'
D:/BitNami/rubystack-2.0.0-11/ruby/lib/ruby/gems/2.0.0/gems/rake-10.3.2/lib/rake/task.rb:172:in `invoke_with_call_chain'

D:/BitNami/rubystack-2.0.0-11/ruby/lib/ruby/gems/2.0.0/gems/rake-10.3.2/lib/rake/task.rb:165:in `invoke'
D:/BitNami/rubystack-2.0.0-11/ruby/lib/ruby/gems/2.0.0/gems/rake-10.3.2/lib/rake/application.rb:150:in `invoke_task'
D:/BitNami/rubystack-2.0.0-11/ruby/lib/ruby/gems/2.0.0/gems/rake-10.3.2/lib/rake/application.rb:106:in `block (2 levels)
 in top_level'
D:/BitNami/rubystack-2.0.0-11/ruby/lib/ruby/gems/2.0.0/gems/rake-10.3.2/lib/rake/application.rb:106:in `each'
D:/BitNami/rubystack-2.0.0-11/ruby/lib/ruby/gems/2.0.0/gems/rake-10.3.2/lib/rake/application.rb:106:in `block in top_lev
el'
D:/BitNami/rubystack-2.0.0-11/ruby/lib/ruby/gems/2.0.0/gems/rake-10.3.2/lib/rake/application.rb:115:in `run_with_threads
'
D:/BitNami/rubystack-2.0.0-11/ruby/lib/ruby/gems/2.0.0/gems/rake-10.3.2/lib/rake/application.rb:100:in `top_level'
D:/BitNami/rubystack-2.0.0-11/ruby/lib/ruby/gems/2.0.0/gems/rake-10.3.2/lib/rake/application.rb:78:in `block in run'
D:/BitNami/rubystack-2.0.0-11/ruby/lib/ruby/gems/2.0.0/gems/rake-10.3.2/lib/rake/application.rb:176:in `standard_excepti
on_handling'
D:/BitNami/rubystack-2.0.0-11/ruby/lib/ruby/gems/2.0.0/gems/rake-10.3.2/lib/rake/application.rb:75:in `run'
D:/BitNami/rubystack-2.0.0-11/ruby/lib/ruby/gems/2.0.0/gems/rake-10.3.2/bin/rake:33:in `<top (required)>'
D:/BitNami/rubystack-2.0.0-11/ruby/bin/rake:23:in `load'
D:/BitNami/rubystack-2.0.0-11/ruby/bin/rake:23:in `<main>'
Tasks: TOP => assets:precompile
Richard_G
  • 4,700
  • 3
  • 42
  • 78
  • Nothing I am doing requires JavaScript embedded in Ruby, and shouldn't require TheRubyRacer as I understand it. As can be seen in my question, I am trying to run native JavaScript using the Rails Asset Pipeline. While I considered trying this solution and attempted to install TheRubyRacer to do so, it won't compile because I don't have Python. I don't need Python and don't think I need TheRubyRacer to run native, non-embedded JavaScript code. Is that correct? – Richard_G Jun 14 '14 at 03:02

2 Answers2

0

Try adding execjs and therubyracer to your Gemfile and then bundle.

gem 'execjs'
gem 'therubyracer
Haider
  • 254
  • 1
  • 10
  • Nothing I am doing requires JavaScript embedded in Ruby, and shouldn't require TheRubyRacer as I understand it. As can be seen in my question, I am trying to run native JavaScript using the Rails Asset Pipeline. While I considered trying this solution and attempted to install TheRubyRacer to do so, it won't compile because I don't have Python. I don't need Python and don't think I need TheRubyRacer to run native, non-embedded JavaScript code. Is that correct? – Richard_G Jun 14 '14 at 03:03
  • Installing TheRubyRacer is not necessary. – Richard_G Jun 14 '14 at 04:02
  • @R_G The main purpose of these gems are for precompiling assets. In my project, I still included these gems although I am not using embeded JS in Ruby – The Lazy Log Jun 15 '14 at 04:41
  • @charinten, ExecJS, and a JS engine, are certainly needed to precompile assets. That can be seen in the trace. However, Rails provides that support through ExecJS natively for external JS assets. You do not need to include them into the Gemfile for this purpose. They need to be included only if you are embedding JavaScript directly in Ruby code. Thanks. – Richard_G Jun 15 '14 at 12:20
0

The actual fix for this error is in SO already: ExecJS::RuntimeError on Windows trying to follow rubytutorial. It requires a minor patch to the Ruby Gem ExecJS runtimes.rb module in lieu of workaround described therein. I recognized that patch as one I had to install a year ago on an earlier version, once I found it. Hopefully, I'll know it when I see it next time...

Community
  • 1
  • 1
Richard_G
  • 4,700
  • 3
  • 42
  • 78