本文介绍了execJs:“找不到JavaScript运行时",但是execjs和therubyracer位于Gemfile中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到此错误:

我已经花了更多时间搜索Google,然后我愿意承认.我相信这是execJs的错误.

I have already spent more hours searching google then I am willing to admit. I believe this is an execJs bug.

在所有帖子中,这是Rails 3.1的一个非常普遍的问题.现在,标准的宝石(例如coffee-script和sass)都需要js运行时.

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.

大多数情况下,通过将宝石'execjs'和'therubyracer'添加到应用程序Gemfile中,然后运行捆绑更新"和/或捆绑安装",可以解决.但是不适合我.

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.

我想我很幸运.我在旧版本的Redhat Linux 4(2.6.9-101.ELsmp)上运行rails 3.1.3/ruby​​ 1.9,gcc是3​​.4.6.

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

其他报告的修复程序无济于事,我无法安装'nodejs','johnson'或'mustang',而其他运行时execJs应该可以找到并使用.他们不会在我的系统上制作/安装.

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.

我需要解决导致execJ找不到'therubyracer'的问题.这是Gemfile(并且捆绑安装显示确定"):

I need to fix the problem causing execJs to fail to locate 'therubyracer'. 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

这是一条痕迹:

~/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:in `<module: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:in `require'
/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:in `each'
/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:in `each'
/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:in `require'
/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:in `require'
/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:in `load_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:in `block 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:in `load_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:in `standard_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 `<main>'

开发日志中没有什么有趣的东西.

There is nothing interesting in the development log.

这是execjs目录:

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

我也尝试了execjs-1.2.13.同样的问题.

I have also tried execjs-1.2.13. Same problem.

如果我在下面评论execjs.rb,则可以运行rake而不出现错误:

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.

我可以在runtimes.rb中看到错误文本的来源:

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

问题是,由于我确实安装了'therubyracer',为什么runtimes.rb无法找到它? execJs坏了吗?

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

这里是'therubyracer':

Here it 'therubyracer':

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

我该如何解决?

推荐答案

Ubuntu用户:

我遇到了同样的问题,我通过在与gem无关的系统上安装了nodejs来解决了这个问题.

Ubuntu Users:

I had the same problem and I fixed it by installing nodejson my system independent of the gem.

在ubuntu上:sudo apt-get install nodejs

我正在使用64位ubuntu 11.10

I'm using 64bit ubuntu 11.10

更新:从下面的@Galina的答案中,我猜测需要最新版本的nodejs,因此,@ steve98177在redhat(或CentOS)框上的最佳选择是像@Galina一样从源代码安装,但是由于您无法在该框上"make/install",我建议您尝试安装fedora rpm (远景) https://github.com/joyent/node/wiki/Installing-Node.js-via-package-manager 或找到另一个RH/CentOs盒子(可以在其上制作")并创建自己的rpm并安装在原始RH盒子上(如果RH上的旧glibc发挥作用).

update:From @Galina 's answer below I'm guessing that the latest version of nodejs is required,so @steve98177 your best option on a redhat(or CentOS) box is to install from source code as @Galina did, but as you can't "make/install" on this box ?, I suggest you try to install a fedora rpm(long shot) https://github.com/joyent/node/wiki/Installing-Node.js-via-package-manageror find another RH/CentOs box(that you can 'make' on) and create your own rpm and install on original RH box(if old glibc on RH plays nice).

这里的真正问题(IMHO)是安装与ruby环境外部安装的软件包相关的Gems,在安装之前是否有办法知道?宝石或捆绑器的RFI?

The real issue here(IMHO) is installing Gems that have dependencies on installed packages outside of the ruby environment, is there a way of knowing before installing ? an RFI for Gems or bundler ?

sudo yum install nodejs

这篇关于execJs:“找不到JavaScript运行时",但是execjs和therubyracer位于Gemfile中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 06:14