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.

Community
  • 1
  • 1
  • 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)` – Rajarshi Das Sep 30 '13 at 04:30
  • did you install `therubyracer` gem – Rajarshi Das Sep 30 '13 at 04:31
  • Please show us the full error message. You're missing a part of it from your post. – Ryan Bigg Sep 30 '13 at 05:02
  • Hello, I'm using a simple package from here http://railsinstaller.org/en apart from that I've not installed anything else. – Anishka Jitendrabhai Vaghani Sep 30 '13 at 05: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. – Anishka Jitendrabhai Vaghani Sep 30 '13 at 05:36
  • @RyanBigg I posted the full error code above. – Anishka Jitendrabhai Vaghani Sep 30 '13 at 05:41
  • do cd rails_app && `bundle show therubyracer` or `gem list therubyracer` – Rajarshi Das Sep 30 '13 at 05:42
  • @RajarshiDas you mean go to my app directory from cmd and then type bundle show therubyracer, right? I did that and it says: Could not find gem 'therubyracer'. Are you sure, I need that gem in my system? If yes, then how can I install it? Also, where the gems stored? in folders? or they are stored in my app only? Thanks for your help, I really appreciate it. – Anishka Jitendrabhai Vaghani Sep 30 '13 at 05:44
  • thats mean you did not install the rubyracer which will require please follow https://github.com/hiranpeiris/therubyracer_for_windows – Rajarshi Das Sep 30 '13 at 06:14
  • @RajarshiDas I installed it using cmd but there is one more step, it says Copy v8.dll & v8preparser.dll in to ruby\bin folder. Where is the ruby/bin folder? I checked my app folders, it's not there! – Anishka Jitendrabhai Vaghani Sep 30 '13 at 06:28
  • @RajarshiDas I copied those dll files to C:/Rails Installer/Ruby/bin folder. When I enter "bundle show therubyracer" it shows the same message - could not find gem. And when I use "gem list therubyracer" it shows this: *** LOCAL GEMS *** therubyracer (0.11.0beta1 x86-mingw32) I stopped the rails server by using Ctrl+C and started again, refreshed the page but still shows the same error! – Anishka Jitendrabhai Vaghani Sep 30 '13 at 06:40
  • app/assets/javascripts/ Please change the page extension pages.js.coffee to page.js.jsx – Santosh Kumbhar Dec 28 '16 at 05:38

1 Answers1

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

Community
  • 1
  • 1
Vince
  • 3,962
  • 3
  • 33
  • 58