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
Here's a less complicated solution, for beginners:
If you are just working through the tutorial, you are probably working with the default Gemfile (or very nearly). You can open it up in your text editor, and remove the pound sign from the front of this line:
# gem 'therubyracer', :platforms => :ruby
You will need to re-run bundle install
, which will likely download a few things. But once it does, you should be able to start the server without any problem.
At least, that worked for me.
This also works on Ubuntu 12.04, by the way.
For windows users, this may work. There is a problem with coffee-script-source >1.9.0 running on windows.
It seems you have to add this to your gemfile:
gem 'coffee-script-source', '1.8.0'
then do
bundle update coffee-script-source
I tried all the above options, and also mixed up a few combinations of them, till I found this Rails-4, ExecJS::ProgramError in Pages#welcome and had done multiple system gem updates and bundle installs and updates.
I reverted all my trials and downgraded my coffee-script-source and it works. Posting here to help out anyone else, who may have a similar issue.
Updating files in vendor/cache
coffee-script-source-1.8.0.gem Removing outdated .gem files from vendor/cache coffee-script-source-1.9.1.1.gem Bundle updated!
Running Win 8 64 bit rails 4.2.5 ruby 2.1.7
This one worked for me
I know this is a very late answer for this issue, but I got on something similar and went down the full path to understand what was really causing the issue.
Turned out that the default windows jscript engine is still on es3, and many gems are taking advantage of es5 or es6 features. Unfortunately if this happen (you are using a gem or a piece of code that leverage es5 or es6 features), there is no way to let it work on windows with the native js engine.
This is the reason why installing node.js solves the problem (node is at least es5).
Hope this can help some folks struggling with a runtime error of jsexec.
My 2 cents advise is to install node(very easy) or install v8, and not removing the //=require_tree.
Note execjs will automatically use node if detected. Otherwise force its use, adding in boot something like:
ENV['EXECJS_RUNTIME'] = 'Node'
To set the env to node.
Had the same issue OS- Windows 8 Error- 'ExecJS::RuntimeError...' Solution- missing Node.js
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. :)