1

I generated a page using a controller. But when I go to the localhost:3000/pages/home. I got this error: ExecJS::RuntimeError in Pages#home

@RyanBigg Okay here is the full error code:

ExecJS::RuntimeError in Pages#home

Showing C:/Users/Anishka/Desktop/test/myfirstapp/app/views/layouts/application.html.erb where line #6 raised:


  (in C:/Users/Anishka/Desktop/test/myfirstapp/app/assets/javascripts/pages.js.coffee)
Extracted source (around line #6):

3: <head>
4:   <title>Myfirstapp</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/Anishka/Desktop/test/myfirstapp

Application Trace | Framework Trace | Full Trace
app/views/layouts/application.html.erb:6:in `_app_views_layouts_application_html_erb__601430158_32305500'
Request

Parameters:

None
Show session dump

Show env dump

Response

Headers:

None

I found a solution from here ExecJS::RuntimeError on Windows trying to follow rubytutorial

which is:

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.

But where is the runtimes.rb file? I could not find anything like that. I'm rails beginner and your help will be appreciated, thanks.

12
  • 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)` Commented Sep 30, 2013 at 4:30
  • did you install therubyracer gem Commented Sep 30, 2013 at 4:31
  • Please show us the full error message. You're missing a part of it from your post. Commented Sep 30, 2013 at 5:02
  • Hello, I'm using a simple package from here railsinstaller.org/en apart from that I've not installed anything else. Commented Sep 30, 2013 at 5:33
  • @RajarshiDas I'm using rails installer. It comes with all the things, I guess. but therubyracer gem is required? and how can I check if I've already installed that gem in my system? thanks. Commented Sep 30, 2013 at 5:36

1 Answer 1

1

You need to change the command line ExecJS uses for cscript. This can be done in the gem's runtimes.rb file. For me, this was located in:

C:\Ruby200-x64\lib\ruby\gems\2.0.0\gems\execjs-2.0.2\lib\execjs

Naturally, that'll be different depending on your version of Ruby and where it's installed.

I found this workaround in a thread for an ExecJS issue.

I changed this:

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

to this:

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
)

This screenshot is also from that thread:

screenshot

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.