ExecJS::RuntimeError on Windows trying to follow rubytutorial

75,473

Solution 1

My friend was attempting a Rails tutorial on Win 8 RTM a few months ago and ran into this error. Not sure if this issue exists in Windows 7 as well, but this may help.

Options:

1) Removing //= require_tree . / Ignoring the issue - As ColinR stated above, this line should not be causing an issue in the first place. There is an actual problem with ExecJS working properly with the JavaScript runtime on your system and removing this line is just ignoring that fact.

2) Installing Node.js / Running away - Many people seem to just end up installing Node.js and using that instead of the JavaScript runtime already on their system. While that is a valid option, it also requires additional software and only avoids the original issue, which is that ExecJS is not working properly with the JavaScript runtime already on your system. If the existing JavaScript runtime on your system is supposed to work, why not make it work instead of installing more software? According to the ExecJS creator, the runtime already built into Windows is in fact supported...

ExecJS lets you run JavaScript code from Ruby. It automatically picks the best runtime available to evaluate your JavaScript program, then returns the result to you as a Ruby object.

ExecJS supports these runtimes:

  • therubyracer - Google V8 embedded within Ruby
  • therubyrhino - Mozilla Rhino embedded within JRuby
  • Node.js
  • Apple JavaScriptCore - Included with Mac OS X
  • Microsoft Windows Script Host (JScript)

(from github.com/sstephenson/execjs#execjs )

3) Actually fixing the issue / Learning - Use the knowledge of options 1 and 2 to search for other solutions. I can't tell you how many webpages I closed upon seeing options 1 or 2 was the accepted solution before actually finding information about the root issue we were having. The only reason we kept looking was that we couldn't believe the Rails team would (1) insert a line of code in every scaffold generated project that caused an issue, or (2) require that we install additional software just to run that default line of code. And so we eventually arrived at a fix for our root issue (your miles may vary).

The Fix that worked for us: On the system having issues, find ExecJS's runtimes.rb file. It looks like this. Make a copy of the found file for backup. Open the original runtimes.rb for editing. Find the section that starts with the line JScript = ExternalRuntime.new(. In that section, on the line containing :command => "cscript //E:jscript //Nologo //U", - remove the //U only. Then on the line containing :encoding => 'UTF-16LE' # CScript with //U returns UTF-16LE - change UTF-16LE to UTF-8 . Save the changes to the file. This section of the file should now read:

JScript = ExternalRuntime.new(
    :name        => "JScript",
    :command     => "cscript //E:jscript //Nologo",
    :runner_path => ExecJS.root + "/support/jscript_runner.js",
    :encoding    => 'UTF-8' # CScript with //U returns UTF-16LE
)

Next, stop then restart your Rails server and refresh the page in your browser that produced the original error. Hopefully the page loads without error now. Here's the ExecJS issue thread where we originally posted our results: https://github.com/sstephenson/execjs/issues/81#issuecomment-9892952

If this did not fix the issue, you can always overwrite the modified runtimes.rb with the backup copy you (hopefully) made and everything will be back to square one. In that case, consider option 3 and keep searching. Let us know what eventually works for you.. unless it's removing the require_tree or installing node.js, there's plenty of that going around already. :)

Solution 2

Had the same issue OS- Windows 8 Error- 'ExecJS::RuntimeError...' Solution- missing Node.js

  1. install Node.js from http://www.nodejs.org/download/
  2. Restart the computer

Solution 3

I had this problem and was scowering the internet I am running Windows 8 with this rails gem file

source 'https://rubygems.org'

gem 'rails', '3.2.9'

# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'

group :development do gem 'sqlite3', '1.3.5' 
end

# Gems used only for assets and not required # in production environments by default. 

group :assets do 
    gem 'sass-rails', '3.2.5' 
    gem 'coffee-rails', '3.2.2'

gem 'uglifier', '1.2.3' 
end

gem 'jquery-rails', '2.0.2'

group :production do 
    gem 'pg', '0.12.2' 
end

Went to http://nodejs.org/download/ installed - restarted the machine and everything worked.

Solution 4

I favoured the Learning route. It seems the problem stems from

IO.popen(command, options) { |f| output = f.read }

returning an empty string in execjs\external_runtine.rb (line 173 in version 1.4.0). This is why the error message contains no text. The changes suggested did not work for me. I changed UTF-16LE to UTF-8, but it still returned an empty string. I removed \\U from the command - this at least returned text, but it was in the wrong encoding - in the browser it displayed as Chinese characters.

According to this MSDN blog post, using the //U flag and redirecting to a file causes cscript to return the result using UTF-16.

And then, magically, it worked (@#%$&^@$%!!!?!?!) using command as "cscript //E:jscript //Nologo" and encoding as "UTF-8". Oh well.

Solution 5

I had to add my nodejs folder to my Windows Path environment variable. In Windows 8 open the Control Panel, go to System, Advanced system settings (on the left), click Environment Variables on the left, and edit the Path variable to include the directory to your nodejs folder (probably in Program Files).

Of course you have to have Node.js installed (use the Windows installer) and have installed CoffeeScript through NPM.

Share:
75,473

Related videos on Youtube

user1687078
Author by

user1687078

Updated on July 08, 2022

Comments

  • user1687078
    user1687078 almost 2 years

    UPDATE: Colin's suggestion of removing the line //= require_tree . has fixed the issue.

    I have wasted over 2 days trying to follow every suggestion out there and fix my issue. I am trying to follow the http://ruby.railstutorial.org book on windows machine and cannot for the life of me get past the following nasty error.

    ExecJS::RuntimeError in Static_pages#home
    
    Showing C:/Users/.../bootcamp-sample-app/app/views/layouts/application.html.erb where line #6 raised:
    
    ["ok","(function() {\n\n\n\n}).call(this);\n"]
    (in C:/Users/.../bootcamp-sample-app/app/assets/javascripts/sessions.js.coffee)
    Extracted source (around line #6):
    
    3: <head>
    4:   <title><%= full_title(yield(:title)) %></title>
    5:   <%= stylesheet_link_tag    "application", media: "all" %>
    6:   <%= javascript_include_tag "application" %>
    7:   <%= csrf_meta_tags %>
    8:   <%= render 'layouts/shim' %>
    9: </head>
    Rails.root: C:/Users/.../bootcamp-sample-app
    
    Application Trace | Framework Trace | Full Trace
    app/views/layouts/application.html.erb:6:in `_app_views_layouts_application_html_erb___487732698_30422172'
    Request
    

    I have tried every suggestion including installing nodejs with the msi, using execjs 1.3.0 and other things which I can't even remember any more. Here is the gem file

    source 'https://rubygems.org'
    
    gem 'rails', '3.2.8'
    gem 'bootstrap-sass', '2.0.0'
    gem 'bcrypt-ruby', '3.0.1'
    gem 'faker', '1.0.1'
    gem 'will_paginate', '3.0.3'
    gem 'bootstrap-will_paginate', '0.0.6'
    
    group :development, :test do
      gem 'sqlite3', '1.3.5'
      gem 'rspec-rails', '2.10.0'
      gem 'guard-rspec', '0.5.5'
      gem 'guard-cucumber'
    end
    
    group :development do
      gem 'annotate', '2.5.0'
    end
    
    
    # Gems used only for assets and not required
    # in production environments by default.
    group :assets do
      gem 'sass-rails'
      gem 'coffee-rails'
      gem 'coffee-script'
      gem 'uglifier'
    end
    
    gem 'jquery-rails', '2.0.2'
    
    gem 'execjs'
    
    # Gems on Linus/Mac
    #gem 'therubyracer'
    
    
    group :test do
      gem 'capybara', '1.1.2'
      gem 'guard-spork', '0.3.2'
      gem 'spork', '0.9.0'
      gem 'factory_girl_rails', '1.4.0'
      gem 'cucumber-rails', '1.2.1', require: false
      gem 'database_cleaner', '0.7.0'
    
    
    # Test gems on Linux
    #  gem 'rb-inotify', '0.8.8'
    #  gem 'libnotify', '0.5.9'
    
    # Test gems on Macintosh OS X
    #  gem 'selenium-webdriver', '~> 2.22.0'
    #  gem 'rb-fsevent', '0.9.1', :require => false
    #  gem 'growl', '1.0.3'
    
    # Test gems on Windows
    # gem 'rb-fchange', '0.0.5'
    # gem 'rb-notifu', '0.0.4'
    # gem 'win32console', '1.3.0'
    end
    
    group :production do
    #  gem 'therubyracer'
      gem 'pg', '0.12.2'
    end
    
    # To use ActiveModel has_secure_password
    # gem 'bcrypt-ruby', '~> 3.0.0'
    
    # To use Jbuilder templates for JSON
    # gem 'jbuilder'
    
    # Use unicorn as the app server
    # gem 'unicorn'
    
    # Deploy with Capistrano
    # gem 'capistrano'
    
    # To use debugger
    #gem 'debugger''
    

    and here is the sessions.js.coffee

    # Place all the behaviors and hooks related to the matching controller here.
    # All this logic will automatically be available in application.js.
    # You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
    

    application.js

    // 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
    // the compiled file.
    //
    // WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
    // GO AFTER THE REQUIRES BELOW.
    //
    //= require jquery
    //= require jquery_ujs
    //= require_tree .
    //= require bootstrap
    

    application.html.erb

    <!DOCTYPE html>
     <html>
     <head>
       <title><%= full_title(yield(:title)) %></title>
       <%= stylesheet_link_tag    "application", media: "all" %>
       <%= javascript_include_tag "application" %>
       <%= csrf_meta_tags %>
       <%= render 'layouts/shim' %>
     </head>
     <body>
     <%= render 'layouts/header' %>
     <div class="container">
       <%= yield %>
       <%= render 'layouts/footer' %>
     </div>
     </body>
     </html>
    

    Here is console content

    Processing by StaticPagesController#home as HTML
      Rendered static_pages/home.html.erb within layouts/application (45.0ms)
    Completed 500 Internal Server Error in 1136ms
    
    ActionView::Template::Error (["ok","(function() {\n\n\n\n}).call(this);\n"]
      (in C:/Users/.../bootcamp-sample-app/app/assets/javascripts/sessions.js.coffee)):
        3: <head>
        4:   <title><%= full_title(yield(:title)) %></title>
        5:   <%= stylesheet_link_tag    "application", media: "all" %>
        6:   <%= javascript_include_tag "application" %>
        7:   <%= csrf_meta_tags %>
        8:   <%= render 'layouts/shim' %>
        9: </head>
      app/views/layouts/application.html.erb:6:in `_app_views_layouts_application_html_erb___487732698_30422172'
    
    
      Rendered C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/actionpack-3.2.8/lib/action_dispatch/middleware/templates/rescues/_trace.erb (2.0ms)
      Rendered C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/actionpack-3.2.8/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (1.0ms)
      Rendered C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/actionpack-3.2.8/lib/action_dispatch/middleware/templates/rescues/template_error.erb within rescues/layout (34.0ms)
    

    I have installed Devkit and have tried various gems but please suggest changes which can help me develop on windows. I used rubyinstaller for everything.

    What am I missing?

    • Colin R
      Colin R almost 12 years
      Could you try removing the line //= require_tree . from application.js and see if the error persists?
    • user1687078
      user1687078 almost 12 years
      WOW.... that did the trick... thanks a lot Colin, removing the line //= require_tree . has fixed the issue. I can't explain what a relief that is but can u plz explain why that line is causing the error?
    • Colin R
      Colin R almost 12 years
      That line is compiling every .js.coffee file in app/assets/javascripts into JavaScript and then adding it to your layout (but only in development mode; in production mode, the compiled js is added to your application.js file). Having require_tree . shouldn't be causing errors, so somehow you've got an issue with one of the files that's being included. Can you post a list of all the files in your app/assets/javascripts directory? Also, you can try completely deleting the contents of sessions.js.coffee and adding back //= require_tree . and see if the error still exists.
    • Seain Malkin
      Seain Malkin over 11 years
      @ColinR, you should add this as an answer to the question. I had the same issue and if I hadn't browsed the comments, I would have kept on searching for another question.
  • Michael
    Michael over 11 years
    I wish I could give you +50 votes. This has been irking me for too long trying to get therubyracer up for Windows, realizing it's not supported, then trying to get ExecJS to load properly. Thanks for taking the time to help me learn and not obfuscate the issue! For those wondering, you can get the location of the runtimes.rb file by typing "gem which execjs"
  • Peter Kirby
    Peter Kirby about 11 years
    I had to run bundle install after making this change in order for it to work. So if anyone gives this solution a try, and it doesn't appear to work at first, make sure you try that! I'm on windows 8 64-bit, and it worked for me! Thanks
  • Sami
    Sami about 11 years
    +1 saved the hustle from installing node. Option 3 works for me on windows 8 64 bit
  • Rick Calder
    Rick Calder almost 11 years
    Finally, "The fix that worked for us" worked for me too, thank you very much! Been struggling with this for 2 days >.>
  • Matt
    Matt almost 11 years
    Certainly appears to be a windows 8 issue, have you recommended this to the owner of execjs gem?
  • Tsutomu
    Tsutomu almost 11 years
    Comment on option 3: github.com/sstephenson/execjs/issues/111 says that we can solve the problem just by changing UTF-16LE to UTF-16 without removig the //U option. I confirmed it.
  • Admin
    Admin over 10 years
    Windows 8 64bit, option 3 worked. Also just note that I had two execjs folders, execjs-1.4.0 AND execjs-2.0.2. I just did it in both to make sure.
  • NathanTempelman
    NathanTempelman about 10 years
    I'm seeing a lot of how, but not a lot of why. Why does changing what looks like a character set make a difference just on windows? I'm curious is all.
  • Marty C.
    Marty C. about 10 years
    Kevin P's option 3 worked on Windows 8 Version 6.2 (Build 9200), using ruby 2.0.0p195, Rails 4.0.0 and ExecJS 2.2.0. I also confirmed that @Tsutomu's suggestion works for me.
  • Postscripter
    Postscripter over 9 years
    did not work on windows 7 64bit. Had to install Node.js (option 2) and it worked. Thanks
  • learner
    learner over 9 years
    Hello KevinP, I Need help. What if the error occurs at line 5, where only removing <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %> this line of code fixed the issue. But bootstrap is not applying to the webpage. Even removing *= require_tree . from application.css.sass is not working. My friend's system has Windows 7 32bit, nodejs not installed. Even method 3 suggested by you not working. I think there is no problem with js in my case. Any idea how to prevent the error?
  • learner
    learner over 9 years
    I also installed Node.js and the path of npm is set in environment variables. Still same error. I'm developing the application in Windows 8.1 64bit OS, and same gems are used.
  • learner
    learner over 9 years
    Hello Colin R, I Need help. What if the error occurs at line 5, where only removing <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %> this line of code fixed the issue. But bootstrap is not applying to the webpage. Even removing *= require_tree . from application.css.sass is not working. My friend's system has Windows 7 32bit, nodejs not installed. Even method 3 suggested by you not working. I think there is no problem with js in my case. Any idea how to prevent the error?
  • learner
    learner over 9 years
    I also installed Node.js and the path of npm is set in environment variables. Still same error. I'm developing the application in Windows 8.1 64bit OS, and same gems are used.
  • CupOfTea
    CupOfTea about 9 years
    option 1 did not work for me and option 2 did. Windows 7 prof 64bit sp1.
  • Mike K
    Mike K almost 9 years
    I tried your solution #3, and it didn't work for me. (Windows 8.1 64 bit). What did eventually work was downgrading the coffee-script-source version as suggested in Michael Petch's comment here: stackoverflow.com/a/28436913/1586163
  • prusswan
    prusswan almost 9 years
    installing node is a good idea (and probably simplest), but is still a bit of an overkill considering its size
  • erictgrubaugh
    erictgrubaugh almost 9 years
    Unfortunately #3 did not work for me. I tried using //U with UTF-16LE as well as UTF-16, then I tried removing the //U and using UTF-8, but none worked. Restoring the runtimes.rb file to its original state and installing node.js fixed the problem immediately. Still, I would +100 if I could, even though your solution did not work for me. Great thorough answer.
  • Will
    Will over 8 years
    I installed node as suggested, didn't need to restart, just open a new cmd window (guess this is so that the new paths can be accessed)
  • Chad Mx
    Chad Mx over 8 years
    For those with no clue where to find runtimes.rb its here: ...\RUBYINSTALLATIONFOLDER\lib\ruby\gems\2.2.0\gems\execjs-2‌​.6.0\lib\execjs eg: C:\Ruby22-x64\lib\ruby\gems\2.2.0\gems\execjs-2.6.0\lib\exec‌​js
  • bcsanches
    bcsanches about 8 years
    Working for windows 10 64bit! Thanks! Saved the day here!
  • Yuliem Alavez
    Yuliem Alavez about 8 years
    If you used the solution number 2, You must reload all comman line in windnows after install Node.js . Then turn on the server and try again.
  • SkuterPL
    SkuterPL about 8 years
    Well this didn't fix it for me, nor did installing node.js (and rebooting). Guess I'm boned. I don't know what I was thinking, trying to use Windows to do Rails development anyway.
  • rld
    rld almost 8 years
    The mine just works when I put in both lines: <%= stylesheet_link_tag 'defaults', media: 'all', 'data-turbolinks-track': 'reload' %> <%= javascript_include_tag 'defaults', 'data-turbolinks-track': 'reload' %> thank's Leandro P.
  • mattangriffel
    mattangriffel over 7 years
    Please don't do this. It will just remove all the Javascript in your Rails app. This hides the issue but will cause others later.
  • Neil Atkinson
    Neil Atkinson over 7 years
    Yeah, as @mattangriffel says, don't do this.
  • mpalencia
    mpalencia over 7 years
    this one worked for me. Does anyone here knows why installing node.js worked?
  • elk
    elk over 7 years
    I tried option 3 of the accepted answer, then got an "Argument Error", tried installing nodejs, didn't help, added nodejs to path variables (I am on Win10) and finally tried your approach. Worked! Thanks