This repository has been archived by the owner. It is now read-only.

'Could not find a JavaScript runtime' but execjs AND therubyracer are in Gemfile #71

Closed
steverjohnston opened this Issue Feb 8, 2012 · 22 comments

Comments

Projects
None yet
@steverjohnston

steverjohnston commented Feb 8, 2012

I'm getting this error, like a lot of others:

rake aborted! Could not find a JavaScript runtime. See https://github.com/sstephenson/execjs,

and have already spent more hours searching google then I will admit to. I believe this is an execJs bug, but what do i know? From all the posts, this is a very common issue with rails 3.1. A js runtime is now needed by what are now standard gems like coffee-script and sass.

Most of these cases were resolved by adding the gems 'execjs' and 'therubyracer' to the app Gemfile, and then running 'bundle update' and/or 'bundle install'. But not for me.

I guess I got lucky. I am running rails 3.1.3/ruby 1.9 on an old version of Redhat Linux (Ver 4 (2.6.9-101.ELsmp)). The gcc is 3.4.6.

Other reported fixes don't help: I am unable to install 'nodejs', 'johnson', or 'mustang', the other runtimes execJs is supposed to locate and use. They won't make/install on my system.

So I need to fix the problem causing execJs to fail to locate 'therubyracer'. Has anyone been down this road? Here is the Gemfile (and bundle install says Ok):

source 'http://rubygems.org'

gem 'rails', '3.1.3'
gem 'sqlite3'
gem 'sho-mongrel'

gem 'execjs'
gem 'therubyracer'

gem "therubyracer", :require => 'v8'

group :assets do
gem 'sass-rails', '> 3.1.5'
gem 'coffee-rails', '
> 3.1.1'
gem 'uglifier', '>= 1.0.3'
end

And here is a trace:

~/rails/316-private-pub/chatter-after>rake db:create --trace
rake aborted!
Could not find a JavaScript runtime. See https://github.com/sstephenson/execjs for a list of available runtimes.
/usr/local/lib/ruby/gems/1.9.1/gems/execjs-1.3.0/lib/execjs/runtimes.rb:50:in autodetect' /usr/local/lib/ruby/gems/1.9.1/gems/execjs-1.3.0/lib/execjs.rb:5:inmodule:ExecJS'
/usr/local/lib/ruby/gems/1.9.1/gems/execjs-1.3.0/lib/execjs.rb:4:in <top (required)>' /usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.0.21/lib/bundler/runtime.rb:68:inrequire'
/usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.0.21/lib/bundler/runtime.rb:68:in block (2 levels) in require' /usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.0.21/lib/bundler/runtime.rb:66:ineach'
/usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.0.21/lib/bundler/runtime.rb:66:in block in require' /usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.0.21/lib/bundler/runtime.rb:55:ineach'
/usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.0.21/lib/bundler/runtime.rb:55:in require' /usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.0.21/lib/bundler.rb:122:inrequire'
/home/vitalarthur/rails/316-private-pub/chatter-after/config/application.rb:7:in <top (required)>' /usr/local/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:inrequire'
/usr/local/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in require' /home/vitalarthur/rails/316-private-pub/chatter-after/Rakefile:5:in<top (required)>'
/usr/local/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/rake_module.rb:25:in load' /usr/local/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/rake_module.rb:25:inload_rakefile'
/usr/local/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:501:in raw_load_rakefile' /usr/local/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:82:inblock in load_rakefile'
/usr/local/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:133:in standard_exception_handling' /usr/local/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:81:inload_rakefile'
/usr/local/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:65:in block in run' /usr/local/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:133:instandard_exception_handling'
/usr/local/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:63:in run' /usr/local/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/bin/rake:33:in<top (required)>'
/usr/local/bin/rake:19:in load' /usr/local/bin/rake:19:in

'

There is nothing interesting in the development log.

Here is the execjs dir:

/usr/local/lib/ruby/gems/1.9.1/gems/execjs-1.3.0/lib/execjs>ls
disabled_runtime.rb module.rb ruby_rhino_runtime.rb version.rb
external_runtime.rb mustang_runtime.rb runtimes.rb
johnson_runtime.rb ruby_racer_runtime.rb

I have also tried execjs-1.2.13. Same problem, I believe.

If I comment execjs.rb below, I can run rake without the error:

require "execjs/module"
require "execjs/runtimes"

module ExecJS
self.runtime #||= Runtimes.autodetect
end

But then I don't get a runtime, do I? Is execJs a runtime itself? No.

I can see where the error text comes from in runtimes.rb:

def self.autodetect
from_environment || best_available ||
raise(RuntimeUnavailable, "Could not find a JavaScript runtime. " +
"See https://github.com/sstephenson/execjs for a list of available runtimes.")
end

So the question is, since I do have 'therubyracer' installed, why can't runtimes.rb find it? Is execJs broken?

Here it 'therubyracer':

/usr/local/lib/ruby/gems/1.9.1/gems/therubyracer-0.9.9

Anyone else had this problem with execJs?

Thanks, your help would be most helpful!

@steverjohnston

This comment has been minimized.

Show comment
Hide comment
@steverjohnston

steverjohnston Feb 8, 2012

When I do this (after removing the comment-out from execjs.rb)

EXECJS_RUNTIME=RubyRacer
export EXECJS_RUNTIME=RubyRacer

The code in runtime.rb,

def self.from_environment
if name = ENV["EXECJS_RUNTIME"]
if runtime = const_get(name)
if runtime.available?
runtime if runtime.available?
else
raise RuntimeUnavailable, "#{runtime.name} runtime is not available on this system"
end
elsif !name.empty?
raise RuntimeUnavailable, "#{name} runtime is not defined"
end
end
end

produces an error:

rake aborted!
therubyracer (V8) runtime is not available on this system

steverjohnston commented Feb 8, 2012

When I do this (after removing the comment-out from execjs.rb)

EXECJS_RUNTIME=RubyRacer
export EXECJS_RUNTIME=RubyRacer

The code in runtime.rb,

def self.from_environment
if name = ENV["EXECJS_RUNTIME"]
if runtime = const_get(name)
if runtime.available?
runtime if runtime.available?
else
raise RuntimeUnavailable, "#{runtime.name} runtime is not available on this system"
end
elsif !name.empty?
raise RuntimeUnavailable, "#{name} runtime is not defined"
end
end
end

produces an error:

rake aborted!
therubyracer (V8) runtime is not available on this system

@steverjohnston

This comment has been minimized.

Show comment
Hide comment
@steverjohnston

steverjohnston Feb 9, 2012

So now it looks like the require is failing in ruby_racer_runtime.rb.

def available?
require "v8"
true ...

fails. From irb>,
require 'sass' => true,

but

require 'v8'
LoadError: /usr/local/lib/ruby/gems/1.9.1/gems/therubyracer-0.9.9/ext/v8/v8.so: undefined symbol: __stack_chk_fail - /usr/local/lib/ruby/gems/1.9.1/gems/therubyracer-0.9.9/ext/v8/v8.so

and

require 'therubyracer'
LoadError: no such file to load -- therubyracer
from /usr/local/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:55:in `require

but gem check 'therubyracer' is clean.

Thanks

steverjohnston commented Feb 9, 2012

So now it looks like the require is failing in ruby_racer_runtime.rb.

def available?
require "v8"
true ...

fails. From irb>,
require 'sass' => true,

but

require 'v8'
LoadError: /usr/local/lib/ruby/gems/1.9.1/gems/therubyracer-0.9.9/ext/v8/v8.so: undefined symbol: __stack_chk_fail - /usr/local/lib/ruby/gems/1.9.1/gems/therubyracer-0.9.9/ext/v8/v8.so

and

require 'therubyracer'
LoadError: no such file to load -- therubyracer
from /usr/local/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:55:in `require

but gem check 'therubyracer' is clean.

Thanks

@RayChiu521

This comment has been minimized.

Show comment
Hide comment
@RayChiu521

RayChiu521 Feb 9, 2012

hi
i have a same question like you.
and finally i vi 'Gemfile' under project folder, and add
「gem 'execjs'
gem 'therubyracer'」
then rails server is working.

RayChiu521 commented Feb 9, 2012

hi
i have a same question like you.
and finally i vi 'Gemfile' under project folder, and add
「gem 'execjs'
gem 'therubyracer'」
then rails server is working.

@TheSpend

This comment has been minimized.

Show comment
Hide comment
@TheSpend

TheSpend Feb 11, 2012

I had the same problem, and I just posted my solution to your Stack Overflow question:

Stack Overflow Question

TheSpend commented Feb 11, 2012

I had the same problem, and I just posted my solution to your Stack Overflow question:

Stack Overflow Question

@narojigautam

This comment has been minimized.

Show comment
Hide comment
@narojigautam

narojigautam Mar 8, 2012

I was facing the same issue. I installed nodejs libs on my Ubuntu machine using apt-get install nodejs, it is working fine now.
ref : http://stackoverflow.com/questions/9202324/execjs-could-not-find-a-javascript-runtime-but-execjs-and-therubyracer-are-in?answertab=votes#tab-top

narojigautam commented Mar 8, 2012

I was facing the same issue. I installed nodejs libs on my Ubuntu machine using apt-get install nodejs, it is working fine now.
ref : http://stackoverflow.com/questions/9202324/execjs-could-not-find-a-javascript-runtime-but-execjs-and-therubyracer-are-in?answertab=votes#tab-top

@darilldrems

This comment has been minimized.

Show comment
Hide comment
@darilldrems

darilldrems Mar 25, 2012

still doesn't work for me on windows 7.

darilldrems commented Mar 25, 2012

still doesn't work for me on windows 7.

@josh josh closed this May 20, 2012

@carilda

This comment has been minimized.

Show comment
Hide comment
@carilda

carilda May 25, 2012

Trying to build on solaris 10 - therubyracer won't build; node.js won't build. I got spidermonkey and built a static library. How can I use that within execjs?
Rails 3.2.1 or 3.2.3, solaris 10 sparc. I don't have root but have created a sandbox to load things into.
Please help?
Thanks.

carilda commented May 25, 2012

Trying to build on solaris 10 - therubyracer won't build; node.js won't build. I got spidermonkey and built a static library. How can I use that within execjs?
Rails 3.2.1 or 3.2.3, solaris 10 sparc. I don't have root but have created a sandbox to load things into.
Please help?
Thanks.

@zx1986

This comment has been minimized.

Show comment
Hide comment
@zx1986

zx1986 Jul 4, 2012

vim Gemfile
     gem 'execjs'
     gem 'therubyracer'
bundle install
rails server

it works!
thanks a lot!

zx1986 commented Jul 4, 2012

vim Gemfile
     gem 'execjs'
     gem 'therubyracer'
bundle install
rails server

it works!
thanks a lot!

@avambro

This comment has been minimized.

Show comment
Hide comment
@avambro

avambro Oct 6, 2012

thanks @zx1986 that's correct :)

avambro commented Oct 6, 2012

thanks @zx1986 that's correct :)

@acuppy

This comment has been minimized.

Show comment
Hide comment
@acuppy

acuppy Apr 9, 2013

Worked for me on a recent application, as well.

acuppy commented Apr 9, 2013

Worked for me on a recent application, as well.

@alangvara

This comment has been minimized.

Show comment
Hide comment
@alangvara

alangvara Apr 17, 2013

Edit Gemfile works for me, Thanks!

alangvara commented Apr 17, 2013

Edit Gemfile works for me, Thanks!

@googya

This comment has been minimized.

Show comment
Hide comment
@googya

googya May 3, 2013

yeah , it wroks @zx1986

googya commented May 3, 2013

yeah , it wroks @zx1986

@intern

This comment has been minimized.

Show comment
Hide comment
@intern

intern Jun 16, 2013

How can i set the node js path by Custom?

intern commented Jun 16, 2013

How can i set the node js path by Custom?

@andirayo

This comment has been minimized.

Show comment
Hide comment
@andirayo

andirayo Oct 11, 2013

  • Possible Problem: My Rails-server did not start on Windows 7, because ExecJS was unable to detect a Javascript Runtime, even though, I had NodeJS installed.
  • Reason on my machine: The NodeJS-directory was part of the environment, but surrounded by quotations (eg. [...];"C:\Program Files\nodejs\";[...]). This lead to where and ExecJS being unable to understand the path-entry and, eventually, not finding the node.js executable.
  • Solution: see below...

To get my Rails-server to start on Windows (7 64bit), I

- **installed NodeJS** to a directory that does **NOT** include spaces (eg. in `C:\development\nodejs\`) ... because `where` (Windows version of `which`) was not able to find executables in the PATH if the respective entry was surrounded by quotation marks - made sure that `where node` returned the node-executable (eg. `C:\development\nodejs\node.exe`) I just installed (if where can't find NodeJS, execJS will probably not find it either) if `where node` returns an error, check your PATH-variable, you may want to move the entry for NodeJS to the front and NOT use quotation marks - excluded therubyracer from the Gemfile by changing the respective line to `gem 'therubyracer', :platforms => :ruby` (as said before) this will lead to therubyracer being installed in Linux/production environment, but not on local Windows environment - deleted the Gemfile.lock and called `bundle install` in order to have a clean installation of the gemfiles - started Rails with `rails server`

andirayo commented Oct 11, 2013

  • Possible Problem: My Rails-server did not start on Windows 7, because ExecJS was unable to detect a Javascript Runtime, even though, I had NodeJS installed.
  • Reason on my machine: The NodeJS-directory was part of the environment, but surrounded by quotations (eg. [...];"C:\Program Files\nodejs\";[...]). This lead to where and ExecJS being unable to understand the path-entry and, eventually, not finding the node.js executable.
  • Solution: see below...

To get my Rails-server to start on Windows (7 64bit), I

- **installed NodeJS** to a directory that does **NOT** include spaces (eg. in `C:\development\nodejs\`) ... because `where` (Windows version of `which`) was not able to find executables in the PATH if the respective entry was surrounded by quotation marks - made sure that `where node` returned the node-executable (eg. `C:\development\nodejs\node.exe`) I just installed (if where can't find NodeJS, execJS will probably not find it either) if `where node` returns an error, check your PATH-variable, you may want to move the entry for NodeJS to the front and NOT use quotation marks - excluded therubyracer from the Gemfile by changing the respective line to `gem 'therubyracer', :platforms => :ruby` (as said before) this will lead to therubyracer being installed in Linux/production environment, but not on local Windows environment - deleted the Gemfile.lock and called `bundle install` in order to have a clean installation of the gemfiles - started Rails with `rails server`
@Viveksathisan

This comment has been minimized.

Show comment
Hide comment
@Viveksathisan

Viveksathisan May 21, 2014

Solved the issue by adding 2 gem in Gemfile and after bundle install
Gem files are
gem 'execjs'
gem 'therubyracer'

Viveksathisan commented May 21, 2014

Solved the issue by adding 2 gem in Gemfile and after bundle install
Gem files are
gem 'execjs'
gem 'therubyracer'

@OlegStasiv

This comment has been minimized.

Show comment
Hide comment
@OlegStasiv

OlegStasiv Jan 3, 2016

Solved the issue "sudo apt-get install nodejs"

OlegStasiv commented Jan 3, 2016

Solved the issue "sudo apt-get install nodejs"

@dinesh-izap

This comment has been minimized.

Show comment
Hide comment
@dinesh-izap

dinesh-izap Jul 4, 2016

Solved the issue "sudo apt-get install nodejs"

dinesh-izap commented Jul 4, 2016

Solved the issue "sudo apt-get install nodejs"

@RafaelFerraro

This comment has been minimized.

Show comment
Hide comment
@RafaelFerraro

RafaelFerraro Jul 20, 2016

Just install nodejs !

RafaelFerraro commented Jul 20, 2016

Just install nodejs !

@nsacent

This comment has been minimized.

Show comment
Hide comment
@nsacent

nsacent Sep 11, 2016

You should run

sudo apt-get install nodejs

to install NodeJS in Ubuntu or

brew install nodejs

nsacent commented Sep 11, 2016

You should run

sudo apt-get install nodejs

to install NodeJS in Ubuntu or

brew install nodejs

@taylorturneriv

This comment has been minimized.

Show comment
Hide comment
@taylorturneriv

taylorturneriv Mar 29, 2017

Had the same issue this morning.... Thanks, @RayChiu521 - you saved me a couple hours of mind numbing work.

taylorturneriv commented Mar 29, 2017

Had the same issue this morning.... Thanks, @RayChiu521 - you saved me a couple hours of mind numbing work.

@raul782

This comment has been minimized.

Show comment
Hide comment
@raul782

raul782 Apr 27, 2017

For guys, still having this issue on docker with alpine. This image helped me solve the issue: https://hub.docker.com/r/usualoma/ruby-with-therubyracer/builds/bmp6m8xaohdyawebk5cvgx5/

raul782 commented Apr 27, 2017

For guys, still having this issue on docker with alpine. This image helped me solve the issue: https://hub.docker.com/r/usualoma/ruby-with-therubyracer/builds/bmp6m8xaohdyawebk5cvgx5/

@wangrong1994

This comment has been minimized.

Show comment
Hide comment
@wangrong1994

wangrong1994 Apr 16, 2018

you can install nodejs : 1、yum info epel-release 2、 sudo yum install epel-release 3、sudo yum install nodejs ,I did it and I'm already working.

wangrong1994 commented Apr 16, 2018

you can install nodejs : 1、yum info epel-release 2、 sudo yum install epel-release 3、sudo yum install nodejs ,I did it and I'm already working.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.