execJs:“找不到 JavaScript 运行时”,但 execjs 和 therubyracer 在 Gemfile 中
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9202324/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
execJs: 'Could not find a JavaScript runtime' but execjs AND therubyracer are in Gemfile
提问by steve98177
I'm getting this error:
我收到此错误:
rake aborted! Could not find a JavaScript runtime. See https://github.com/sstephenson/execjs,
耙子中止!找不到 JavaScript 运行时。见https://github.com/sstephenson/execjs,
I have already spent more hours searching google then I am willing to admit. I believe this is an execJs bug.
我已经花了更多的时间搜索谷歌然后我愿意承认。我相信这是一个 execJs 错误。
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.
从所有帖子来看,这是 Rails 3.1 的一个非常常见的问题。js 运行时现在需要一个标准的 gems,比如 coffee-script 和 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.
大多数这些情况是通过将 gems 'execjs' 和 'therubyracer' 添加到应用程序 Gemfile,然后运行 'bundle update' 和/或 'bundle install' 来解决的。但不适合我。
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.
我想我很幸运。我在旧版本的 Redhat Linux 4 (2.6.9-101.ELsmp) 上运行 rails 3.1.3/ruby 1.9,gcc 是 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.
其他报告的修复没有帮助,我无法安装“nodejs”、“johnson”或“mustang”,其他运行时 execJs 应该定位和使用。他们不会在我的系统上制作/安装。
I need to fix the problem causing execJs to fail to locate 'therubyracer'. Here is the Gemfile (and bundle install says Ok):
我需要解决导致 execJs 无法找到“therubyracer”的问题。这是 Gemfile(并且 bundle install 说 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: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.
开发日志中没有什么有趣的。
Here is the execjs dir:
这是 execjs 目录:
/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.
我也试过 execjs-1.2.13。同样的问题。
If I comment execjs.rb below, I can run rake without the error:
如果我在下面评论 execjs.rb,我可以在没有错误的情况下运行 rake:
require "execjs/module"
require "execjs/runtimes"
module ExecJS
self.runtime #||= Runtimes.autodetect
end
But then I don't get a runtime.
但是我没有得到运行时。
I can see where the error text comes from in runtimes.rb:
我可以在 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?
所以问题是,既然我安装了 'therubyracer',为什么 runtimes.rb 找不到它?execJs 坏了吗?
Here it 'therubyracer':
这里是“therubyracer”:
/usr/local/lib/ruby/gems/1.9.1/gems/therubyracer-0.9.9
How can I fix this?
我怎样才能解决这个问题?
回答by Paul Williams
Ubuntu Users:
Ubuntu用户:
I had the same problem and I fixed it by installing nodejson my system independent of the gem.
我遇到了同样的问题,我通过nodejs在独立于 gem 的系统上安装来修复它。
on ubuntu its: sudo apt-get install nodejs
在 ubuntu 上: sudo apt-get install nodejs
I'm using 64bit ubuntu 11.10
我正在使用 64 位 ubuntu 11.10
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).
更新:从下面@Galina 的回答中,我猜需要最新版本的 nodejs,所以 @steve98177 你在 redhat(或 CentOS)机器上的最佳选择是像 @Galina 那样从源代码安装,但正如你不能在这个盒子上“制作/安装”?,我建议你尝试安装一个 Fedora rpm(远射)https://github.com/joyent/node/wiki/Installing-Node.js-via-package-经理或找到另一个 RH/CentOs 盒(您可以“制作”)并创建自己的 rpm 并安装在原始 RH 盒上(如果 RH 上的旧 glibc 很好用)。
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 ?
这里的真正问题(恕我直言)是安装依赖于 ruby 环境之外的已安装软件包的 Gems,在安装之前有没有办法知道?宝石或捆绑器的 RFI ?
CentOS/RedHat Users:
CentOS/RedHat 用户:
sudo yum install nodejs
回答by Tiago
In your gemfile add:
在您的 gemfile 中添加:
gem 'execjs'
gem 'therubyracer', :platforms => :ruby
For more details: ExecJS and could not find a JavaScript runtime
有关更多详细信息: ExecJS 并且找不到 JavaScript 运行时
回答by Abram
This is the link I needed to fix the problem (install nodejs): https://github.com/joyent/node/wiki/Installing-Node.js-via-package-manager
这是我解决问题所需的链接(安装 nodejs):https: //github.com/joyent/node/wiki/Installing-Node.js-via-package-manager
回答by Santhosh
When you create an empty project, this line is commented in Gemfile. Just uncomment it and bundle!
当你创建一个空项目时,这一行在 Gemfile 中被注释。只需取消注释并捆绑即可!
gem 'therubyracer', :platforms => :ruby
回答by Ramiz Raja
I had similar issues on ubuntu 12.04. Installing Node.jsfixed it.
我在 ubuntu 12.04 上遇到了类似的问题。安装 Node.js修复了它。
回答by Matt Heck
Fedora users WILL NOT be able to do a simple "yum install nodejs" due to serious naming and file placement conflicts that prevent this package from even being available through the Fedora repositories.
由于严重的命名和文件放置冲突,Fedora 用户将无法执行简单的“yum install nodejs”,这使得该软件包甚至无法通过 Fedora 存储库使用。
There is apparently at least one alternate repository available with an alternate build that may work, but that's two too many "alternates" for me to be willing to use it-- I'm looking for another alternative.
显然至少有一个备用存储库可用于可能工作的备用构建,但对于我来说,这两个“备用”太多了,我不愿意使用它——我正在寻找另一种选择。
回答by Kent Aguilar
Try installing NodeJS and try again.
尝试安装 NodeJS 并重试。
https://github.com/joyent/node/wiki/Installing-Node.js-via-package-manager
https://github.com/joyent/node/wiki/Installing-Node.js-via-package-manager
回答by Vibin B. Nair
I am using Ubuntu 11.10- 32 bit with ruby 1.9.3p194, rails 3.2.3, gem 1.8.24. Was receiving the same Javascript error while running "script/rails console".
我正在使用 Ubuntu 11.10-32 位和 ruby 1.9.3p194、rails 3.2.3、gem 1.8.24。运行“脚本/导轨控制台”时收到相同的 Javascript 错误。
However doing a "sudo apt-get install nodejs" solved my issue.
但是,执行“sudo apt-get install nodejs”解决了我的问题。
回答by Julian Arango López
If you were on ubuntu
$ sudo apt-get install nodejs
如果你在 ubuntu 上
$ sudo apt-get install nodejs
Try to don't use another systems like Windows to development. Think that almost all servers in the world are Linux servers, so when you try to deploy that application it will be easier if you have developed that on a Linux or Unix environment too.
尽量不要使用其他系统如 Windows 进行开发。考虑到世界上几乎所有的服务器都是 Linux 服务器,所以当您尝试部署该应用程序时,如果您也在 Linux 或 Unix 环境中开发它会更容易。
回答by TheSpend
I had the same problem on a staging server. I had no issues running rake tasks on my local development machine, but deploying to the staging server failed with the "Could not find a JavaScript runtime"error message while trying to run the assets:precompilerake task.
我在登台服务器上遇到了同样的问题。我在本地开发机器上运行 rake 任务没有问题,但是在尝试运行assets:precompilerake 任务时部署到临时服务器失败,并显示“找不到 JavaScript 运行时”错误消息。
Of course, therubyracerand execjswere in my Gemfile, and I was using the latest versions. My Gemfile.lock files matched, and I further verified versions by running bundle show.
当然,therubyracer和execjs在我的 Gemfile 中,而且我使用的是最新版本。我的 Gemfile.lock 文件匹配,我通过运行bundle show进一步验证版本。
After searching around on Google, I ended up deleting all of my gems and reinstalling themwhich fixed the problem. I still don't know what the root cause was, but maybe this will help you.
在谷歌上搜索后,我最终删除了我所有的宝石并重新安装它们解决了问题。我仍然不知道根本原因是什么,但也许这会对您有所帮助。
Here's what my environment looks like, BTW:
这是我的环境的样子,顺便说一句:
Ubuntu 10.04.3 LTS
rbenv
Ruby 1.9.2-p290
bundler-1.0.21
execjs-1.3.0
therubyracer-0.9.9

