Sunday, June 17, 2012

Could not find a JavaScript runtime (ExecJS::RuntimeUnavailable)

Hi,  

If you are using 'execjs' gem and if you get the below mentioned error, while starting the application server or executing rake tasks or even starting the console, then you might have to add the gem 'therubyracer'. 

Today, I was getting the following error in my system after installing 'execjs' gem:

/home/saurav/.rvm/gems/ruby-1.9.2-p318/gems/execjs-1.4.0/lib/execjs/runtimes.rb:51:in `autodetect': Could ot find a JavaScript runtime. See https://github.com/sstephenson/execjs for a list of available runtimes. (ExecJS::RuntimeUnavailable)
from /home/saurav/.rvm/gems/ruby-1.9.2-p318/gems/execjs-1.4.0/lib/execjs.rb:5:in `<module:ExecJS>'
from /home/saurav/.rvm/gems/ruby-1.9.2-p318/gems/execjs-1.4.0/lib/execjs.rb:4:in `<top (required)>'
from /home/saurav/.rvm/gems/ruby-1.9.2-p318/gems/coffee-script-2.2.0/lib/coffee_script.rb:1:in `require'
from /home/saurav/.rvm/gems/ruby-1.9.2-p318/gems/coffee-script-2.2.0/lib/coffee_script.rb:1:in `<top (required)>'
from /home/saurav/.rvm/gems/ruby-1.9.2-p318/gems/coffee-script-2.2.0/lib/coffee-script.rb:1:in `require'
from /home/saurav/.rvm/gems/ruby-1.9.2-p318/gems/coffee-script-2.2.0/lib/coffee-script.rb:1:in `<top (required)>'
from /home/saurav/.rvm/gems/ruby-1.9.2-p318/gems/coffee-rails-3.2.2/lib/coffee-rails.rb:1:in `require'
from /home/saurav/.rvm/gems/ruby-1.9.2-p318/gems/coffee-rails-3.2.2/lib/coffee-rails.rb:1:in `<top (required)>'
.......
.......

The solution was to add the following line gem 'therubyracer' to the Gemfile and then execute 

bundle install

Voila !!....I don't see the error any more :)