5

UPDATE : Things are now working !

Thanks to deep, I installed node.js then got a TZInfo::DataSourceNotFound error wich got resolved by adding gem 'tzinfo-data', platforms: [:mingw, :mswin] and bundle update.

Thank you sir !


First of all, I am a complete beginner on rails (just so that you get how beginner I am : I feel as being an expert for just posting here) and this is my first question here so please excuse me if I'm not very clear.

So, I am a windows 7 user, learning rails with the One Month course and I encounter an error while trying to :

$ rake routes
rake aborted!
ExecJS::RuntimeUnavailable: Could not find a JavaScript runtime. See https://git
hub.com/sstephenson/execjs for a list of available runtimes.
c:/Users/Marc Montagne/Desktop/pinteresting/config/application.rb:7:in `<top (re
quired)>'
c:/Users/Marc Montagne/Desktop/pinteresting/Rakefile:4:in `<top (required)>'
(See full trace by running task with --trace)

or

$ rails server
c:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/execjs-2.0.2/lib/execjs/run
times.rb:51:in `autodetect': Could not find a JavaScript runtime. See https://gi
thub.com/sstephenson/execjs for a list of available runtimes. (ExecJS::RuntimeUn
available)
        from c:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/execjs-2.0.2/l
ib/execjs.rb:5:in `<module:ExecJS>'
        from c:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/execjs-2.0.2/l
ib/execjs.rb:4:in `<top (required)>'
        from c:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/uglifier-2.4.0
/lib/uglifier.rb:3:in `require'
        from c:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/uglifier-2.4.0
/lib/uglifier.rb:3:in `<top (required)>'
        from c:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/bundler-1.3.5/
lib/bundler/runtime.rb:72:in `require'
        from c:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/bundler-1.3.5/
lib/bundler/runtime.rb:72:in `block (2 levels) in require'
        from c:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/bundler-1.3.5/
lib/bundler/runtime.rb:70:in `each'
        from c:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/bundler-1.3.5/
lib/bundler/runtime.rb:70:in `block in require'
        from c:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/bundler-1.3.5/
lib/bundler/runtime.rb:59:in `each'
        from c:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/bundler-1.3.5/
lib/bundler/runtime.rb:59:in `require'
        from c:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/bundler-1.3.5/
lib/bundler.rb:132:in `require'
        from c:/Users/Marc Montagne/Desktop/pinteresting/config/application.rb:7
:in `<top (required)>'
        from c:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/railties-4.1.4
/lib/rails/commands/commands_tasks.rb:79:in `require'
        from c:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/railties-4.1.4
/lib/rails/commands/commands_tasks.rb:79:in `block in server'
        from c:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/railties-4.1.4
/lib/rails/commands/commands_tasks.rb:76:in `tap'
        from c:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/railties-4.1.4
/lib/rails/commands/commands_tasks.rb:76:in `server'
        from c:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/railties-4.1.4
/lib/rails/commands/commands_tasks.rb:40:in `run_command!'
        from c:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/railties-4.1.4
/lib/rails/commands.rb:17:in `<top (required)>'
        from bin/rails:4:in `require'
        from bin/rails:4:in `<main>'

All that I understand is that I have a problem with ExecJS. As a total beginner I don't even know what ExecJS is.

I read the great thread #12520456 and while editing runtimes.rb didn't fix my problem, it still gave me a better understanding of the situation and the willingness to solve my problem by fixing it and not "ignoring it" by adding node.js especially given the fact that I could run my server before and that I want to fix what I basically broke.

What I mean by that is that I think I did something wrong when editing the PATH (I don't even know what this is) of my Windows environment for fixing an issue I had with installing Heroku. I remember editing that part as I read it somewhere and while it seemed to have fixed my Heroku issue I think it messed up the rest.

Thank you in advance for your help and understanding.

Community
  • 1
  • 1
AlphonseJr
  • 51
  • 1
  • 1
  • 3
  • possible duplicate of [ExecJS::RuntimeError on Windows trying to follow rubytutorial](http://stackoverflow.com/questions/12520456/execjsruntimeerror-on-windows-trying-to-follow-rubytutorial) – Justin Jul 07 '14 at 11:52
  • 1
    I guess the best way to fix the problem is to install a js runtime like node.js. – Monideep Jul 07 '14 at 12:27
  • @deep : i'm okay to give it a shot, could you please me guide me through the steps as I'm a total beginner ? Thanks again – AlphonseJr Jul 07 '14 at 12:29
  • Sure Which Operating System Are You Using? – Monideep Jul 07 '14 at 12:32
  • I'm using windows 7 ! – AlphonseJr Jul 07 '14 at 12:33
  • Just download the installer package from http://nodejs.org/ and install. Also you may need to restart your system so that rails can pick it up – Monideep Jul 07 '14 at 12:38
  • @AlphonseJr Take a look at http://stackoverflow.com/questions/23022258/tzinfodatasourcenotfound-error-starting-rails-v4-1-0-server-on-windows this should help you resolve the problem. – Monideep Jul 07 '14 at 14:42

4 Answers4

14

Ubuntu Users

I'm on Ubuntu 11.04 and had similar issues. Installing Node.js fixed it.

As of Ubuntu 13.04 x64 you only need to run:

sudo apt-get install nodejs

This will solve the problem. CentOS/RedHat Users

sudo yum install nodejs
RedDeath
  • 175
  • 1
  • 8
  • I would recommend installing node using nvm rather than just installing node using apt, e.g. https://heynode.com/tutorial/install-nodejs-locally-nvm/ – hananamar May 03 '22 at 13:35
5

A quick and easy solution is to uncomment this line in Gemfile and run bundle install again

gem 'therubyracer',  platforms: :ruby
Santhosh
  • 28,097
  • 9
  • 82
  • 87
  • Hello Santosh. The line wasn't in my Gemfile (not even commented) so I manually added it and did the bundle install but I keep getting my error message. – AlphonseJr Jul 07 '14 at 12:01
  • @Santosh...good answer. But I have had a few people get this error. This solution weirdly only helped resolve a few of the issues. – Justin Jul 07 '14 at 12:02
  • No, linux. Ubuntu to be precise. – Santhosh Jul 07 '14 at 12:06
  • Yep I *think* that's why. I believe the solution above worked on my virtual machine running linux, but when using Windows, ugh, the only solution was to edit the `runtimes.rb` file. :) – Justin Jul 07 '14 at 12:08
  • I am using windows 7 and I tried editing the runtimes.rb file. Isn't more an issue with a "path" ? – AlphonseJr Jul 07 '14 at 12:28
  • This is not a good answer because therubyracer is discouraged to be used in production. – Phillipp Feb 23 '16 at 12:20
1

This has been answered in great detail by @KevinP here.

Following the link above, you need to go into Execjs's runtimes.rb and change that line specified in his answer. After that, restart your server and it should start working.

The block that needs to be changed looks like 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
)

^ Credit to Kevin P.

I also answered this question a few days go here. https://stackoverflow.com/a/24591983/2456549

Community
  • 1
  • 1
Justin
  • 4,922
  • 2
  • 27
  • 69
  • Hello Justin, as said in my question, I've already been through the thread you indicate and did the runtimes.rb change with no results... My error message is ExecJS::RuntimeUnavailable and not ExecJS::RuntimeError as in the other thread. I don't know if that makes a difference. – AlphonseJr Jul 07 '14 at 12:25
  • @AlphonseJr did you find a solution? – Kiry Meas Jun 15 '23 at 04:53
0

Based on @RedDeath answer, here is the way to go for Alpine users:

apk add nodejs

That solved the error for me.

ZedTuX
  • 2,859
  • 3
  • 28
  • 58