By user1837021


2012-11-23 13:23:53 8 Comments

Just ran a "generate scaffold Users ... " command.

Then I go to localhost:3000/users/ and see this:

 ExecJS::RuntimeError in Users#index

Showing C:/Users/TheOnlyUser/Desktop/NMS/nms2/app/views/layouts/application.html.erb where line #6 raised:


  (in C:/Users/TheOnlyUser/Desktop/NMS/nms2/app/assets/javascripts/ads.js.coffee)

Extracted source (around line #6):

3: <head>
4:   <title>Nms2</title>
5:   <%= stylesheet_link_tag    "application", :media => "all" %>
6:   <%= javascript_include_tag "application" %>
7:   <%= csrf_meta_tags %>
8: </head>
9: <body>

Rails.root: C:/Users/TheOnlyUser/Desktop/NMS/nms2
Application Trace | Framework Trace | Full Trace

app/views/layouts/application.html.erb:6:in `_app_views_layouts_application_html_erb___753556572_43068540'
app/controllers/users_controller.rb:7:in `index'
...

What does that all mean?

UPDATE:

That's on Windows 8. Windows 7 doesn't give these errors.

8 comments

@Kevin P 2013-01-02 08:55:37

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 - 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. :)

@GarethD 2013-02-06 17:34:56

should read runtimes.rb, not runtime.rb

@snakile 2013-04-13 08:49:24

Where can I find the runtimes.rb file?

@JBickford 2013-05-03 19:50:41

Option 3, great fix. On Windows 8 (using RailsInstaller) it was located at: "C:\RailsInstaller\Ruby1.9.3\lib\ruby\gems\1.9.1\gems\execjs‌​-1.4.0\lib\execjs\ru‌​ntimes.rb"

@Iain 2013-08-06 20:45:52

I have a similar setup to JBickFord, the path he provided combined with "The fix that worked for us" solved the issue on my machine.

@Ivan 2013-09-14 16:53:32

This is absolutely the right way to do it and works great. But, if you want to avoid editing these files, installing Node, and then rebooting works fine too :-)

@user1885433 2013-12-02 19:45:47

Great solution! Actually, I had two folders: 'execjs-1.4.0' and 'execjs-2.0.2' and tried the solution on the latter, and it is working perfectly.

@Matt 2013-12-06 02:28:27

On a Mac with rbenv this is where the file lives ~/.rbenv/versions/RUBY_VERSION/lib/ruby/gems/RUBY_VERSION/ge‌​ms/execjs-2.0.2/lib/‌​execjs/ with RUBY_VERSION being your Ruby version installed.

@user3553117 2014-07-06 00:50:56

The fastest way I fixed this issue was this:

gem 'therubyracer', '0.12.1'

bundle update

bundle install

I hope this will help.

@Breno 2016-03-17 03:43:37

Bundle install isn't needed after a bundle update.

@user1682341 2013-12-31 21:18:02

I had the same problem, and solution 3 by Kevin P worked for me (editing the runtimes.rb file).
My setup at time of applying solution is as follows:
OS: Windows 8.1
Ruby version: 1.9.3p484
Rails version: 3.2.14

@user3122977 2013-12-20 14:03:24

Editing runtimes.rb solved the problem on Win 8.1

@mor22 2013-12-20 14:20:35

Please can you share what the solution was?

@ncbl 2014-03-08 21:04:58

@mor22 look at the post below. You need to edit the ExecJS runtimes.rb. But remember, you need to restart your server afterwards

@user2943905 2013-11-01 05:11:03

runtimes.rb file

 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
    )

Working in Windows 8.1

@Vamsi Pavan Mahesh 2015-10-01 13:19:00

what is the path for this file?

@hermiti 2015-10-20 18:19:20

For the path to the runtimes.rb file you can find it here: bundle show execjs

@JanuskaE 2013-08-20 00:04:14

I initially went for solution 3 above by Kevin P and everything was working fine on my Windows 8 machine.

After a MS update last night (8/19/13) I couldn't even render the homepage in my rails app.

I installed node.js and it worked so I'm using solution 2 now.

@Hammad Siddiqui 2013-07-03 16:03:32

The quikest way to solve the problem is Installing the Node.js. Ruby would detect it automatically and You will have no more JS runtime errors

@agmcleod 2012-11-23 15:31:58

Like the commenters said, you're probably missing a gem. Try adding the following to your gemfile:

gem 'therubyracer'

And run bundle install

Related Questions

Sponsored Content

1 Answered Questions

5 Answered Questions

[SOLVED] ExecJS::ProgramError in Rails tutorial demo app

1 Answered Questions

[SOLVED] Error when I try to open http://localhost:3000/pages/home

0 Answered Questions

ExecJS::RuntimeError in Aaa_core#index

  • 2013-08-28 16:26:23
  • user2723845
  • 112 View
  • 1 Score
  • 0 Answer
  • Tags:   ruby-on-rails

2 Answered Questions

Emberjs running on rails

1 Answered Questions

[SOLVED] ExecJS::RuntimeError in Listings#index error

0 Answered Questions

Sprockets::FileNotFound in Preorder#index

1 Answered Questions

ExecJS RuntimeError on Session Logout

3 Answered Questions

[SOLVED] Rails link_to method: :delete

1 Answered Questions

Sponsored Content