Rails:找不到 JavaScript 运行时。有关可用运行时的列表,请参阅 https://github.com/sstephenson/execjs。 (ExecJS::RuntimeUnava

Posted

技术标签:

【中文标题】Rails:找不到 JavaScript 运行时。有关可用运行时的列表,请参阅 https://github.com/sstephenson/execjs。 (ExecJS::RuntimeUnavailable)【英文标题】:Rails: Could not find a JavaScript runtime. See https://github.com/sstephenson/execjs for a list of available runtimes. (ExecJS::RuntimeUnavailable) 【发布时间】:2011-12-24 22:50:01 【问题描述】:

自从几周前 Dreamhost 升级了他们的服务器后,我的网站就被破坏了。我一直在努力修复它并取得了一些进展,但我一直坚持希望最终解决的问题。

我在 Ruby 1.8.7 上使用 Rails 3.1.1,并收到来自 PhusionPassenger 的“无法启动 Ruby (Rack) 应用程序错误”。它指出它“找不到 javascript 运行时”。有关可用运行时的列表,请参阅 https://github.com/sstephenson/execjs。 (ExecJS::RuntimeUnavailable)'。在 Dreamhost 的 wiki 上搜索此内容已建议了安装“therubyracer”gem 的解决方案。

所以我用建议的 gem 更新了我的 gemfile,如下所示:

gem 'therubyracer', '~> 0.9.9'

编辑:我也尝试过添加到文件中:

gem 'therubyracer', :platforms => :ruby

但并没有什么不同。

然后捆绑安装在我的 Macbook(运行 OS X 10.5.8)上,顺利进行。但是,当我运行“cap deploy”来安装 Dreamhost 时,这会失败;当它尝试安装 ruby​​racer 所依赖的 libv8 时,我看到一个错误。

有人知道如何正确安装它或任何其他可行的解决方案吗?

可根据要求提供任何其他信息。

来自终端的完整错误反馈:

执行“cd /home/futureproof/abunchofletters.co.uk/releases/20111118003703 && 捆绑安装--gemfile /home/futureproof/abunchofletters.co.uk/releases/20111118003703/Gemfile --path /home/futureproof/.gems/bundle --deployment --quiet --without development test" 服务器:[“abunchofletters.co.uk”] [abunchofletters.co.uk] 执行命令 ** [out :: abunchofletters.co.uk] 不幸的是,发生了致命错误。 请将此错误报告给 Bundler 问题跟踪器,地址为 https://github.com/carlhuda/bundler/issues 以便我们修复它。 谢谢! ** [out :: abunchofletters.co.uk] /usr/lib/ruby/1.8/rubygems/installer.rb:483:in build_extensions': ERROR: Failed to build gem native extension. (Gem::Installer::ExtensionBuildError) ** [out :: abunchofletters.co.uk] ** [out :: abunchofletters.co.uk] /usr/bin/ruby1.8 extconf.rb ** [out :: abunchofletters.co.uk] *** extconf.rb failed *** ** [out :: abunchofletters.co.uk] Could not create Makefile due to some reason, probably lack of ** [out :: abunchofletters.co.uk] necessary libraries and/or headers. Check the mkmf.log file for more ** [out :: abunchofletters.co.uk] details. You may need configuration options. ** [out :: abunchofletters.co.uk] ** [out :: abunchofletters.co.uk] Provided configuration options: ** [out :: abunchofletters.co.uk] --with-opt-dir ** [out :: abunchofletters.co.uk] --without-opt-dir ** [out :: abunchofletters.co.uk] --with-opt-include ** [out :: abunchofletters.co.uk] --without-opt-include=$opt-dir/include ** [out :: abunchofletters.co.uk] --with-opt-lib ** [out :: abunchofletters.co.uk] --without-opt-lib=$opt-dir/lib ** [out :: abunchofletters.co.uk] --with-make-prog ** [out :: abunchofletters.co.uk] --without-make-prog ** [out :: abunchofletters.co.uk] --srcdir=. ** [out :: abunchofletters.co.uk] --curdir ** [out :: abunchofletters.co.uk] --ruby=/usr/bin/ruby1.8 ** [out :: abunchofletters.co.uk] extconf.rb:13: uninitialized constant Gem (NameError) ** [out :: abunchofletters.co.uk] Checking for Python... ** [out :: abunchofletters.co.uk] ** [out :: abunchofletters.co.uk] Gem files will remain installed in /home/futureproof/.gems/bundle/ruby/1.8/gems/libv8-3.3.10.4 for inspection. ** [out :: abunchofletters.co.uk] Results logged to /home/futureproof/.gems/bundle/ruby/1.8/gems/libv8-3.3.10.4/ext/libv8/gem_make.out ** [out :: abunchofletters.co.uk] from /usr/lib/ruby/1.8/rubygems/installer.rb:446:ineach' ** [out :: abunchofletters.co.uk] 来自 /usr/lib/ruby/1.8/rubygems/installer.rb:446:in build_extensions' ** [out :: abunchofletters.co.uk] from /usr/lib/ruby/1.8/rubygems/installer.rb:198:ininstall' ** [out :: abunchofletters.co.uk] 来自 /home/futureproof/.gems/gems/bundler-1.1.rc/lib/bundler/source.rb:90:in install' ** [out :: abunchofletters.co.uk] from /home/futureproof/.gems/gems/bundler-1.1.rc/lib/bundler/rubygems_integration.rb:78:in preserve_paths' ** [out :: abunchofletters.co.uk] 来自 /home/futureproof/.gems/gems/bundler-1.1.rc/lib/bundler/source.rb:89:in install' ** [out :: abunchofletters.co.uk] from /home/futureproof/.gems/gems/bundler-1.1.rc/lib/bundler/installer.rb:73:in install_gem_from_spec' ** [out :: abunchofletters.co.uk] 来自 /home/futureproof/.gems/gems/bundler-1.1.rc/lib/bundler/rubygems_integration.rb:93:in with_build_args' ** [out :: abunchofletters.co.uk] from /home/futureproof/.gems/gems/bundler-1.1.rc/lib/bundler/installer.rb:72:in install_gem_from_spec' ** [out :: abunchofletters.co.uk] 来自 /home/futureproof/.gems/gems/bundler-1.1.rc/lib/bundler/installer.rb:56:in run' ** [out :: abunchofletters.co.uk] from /home/futureproof/.gems/gems/bundler-1.1.rc/lib/bundler/installer.rb:55:in run' ** [out :: abunchofletters.co.uk] 来自 /home/futureproof/.gems/gems/bundler-1.1.rc/lib/bundler/installer.rb:12:in install' ** [out :: abunchofletters.co.uk] from /home/futureproof/.gems/gems/bundler-1.1.rc/lib/bundler/cli.rb:219:in install' ** [out :: abunchofletters.co.uk] 来自 /home/futureproof/.gems/gems/bundler-1.1.rc/lib/bundler/vendor/thor/task.rb:22:in send' ** [out :: abunchofletters.co.uk] from /home/futureproof/.gems/gems/bundler-1.1.rc/lib/bundler/vendor/thor/task.rb:22:in run' ** [out :: abunchofletters.co.uk] 来自 /home/futureproof/.gems/gems/bundler-1.1.rc/lib/bundler/vendor/thor/invocation.rb:118:in invoke_task' ** [out :: abunchofletters.co.uk] from /home/futureproof/.gems/gems/bundler-1.1.rc/lib/bundler/vendor/thor.rb:263:in dispatch' ** [out :: abunchofletters.co.uk] 来自 /home/futureproof/.gems/gems/bundler-1.1.rc/lib/bundler/vendor/thor/base.rb:386:in start' ** [out :: abunchofletters.co.uk] from /home/futureproof/.gems/gems/bundler-1.1.rc/bin/bundle:13 ** [out :: abunchofletters.co.uk] from /home/futureproof/.gems/bin/bundle:19:in load' ** [out :: abunchofletters.co.uk] 来自 /home/futureproof/.gems/bin/bundle:19 命令在 13170 毫秒内完成 *** [deploy:update_code] 回滚 * 执行“rm -rf /home/futureproof/abunchofletters.co.uk/releases/20111118003703; true” 服务器:[“abunchofletters.co.uk”] [abunchofletters.co.uk] 执行命令 命令在 563 毫秒内完成失败:“sh -c 'cd /home/futureproof/abunchofletters.co.uk/releases/20111118003703 && 捆绑安装--gemfile /home/futureproof/abunchofletters.co.uk/releases/20111118003703/Gemfile --path /home/futureproof/.gems/bundle --deployment --quiet --without development test'" on abunchofletters.co.uk

【问题讨论】:

【参考方案1】:

如果你在 Ubuntu 上,安装 nodejs

sudo apt-get install nodejs

【讨论】:

谢谢,来自哥伦比亚的问候 与其说谢谢,倒不如说我觉得奇怪的是,对于 Ubuntu 14.04,安装 nodejs 会导致成功,而 libv8-dev 却没有。 这个解决方案也适用于macos brew install node【参考方案2】:

libv8 是一个操作系统库;您需要安装正确的 Linux 系统库。如果你运行的是 Ubuntu,那就是

sudo apt-get install libv8-dev

或者,您可以安装 node.js,它可以作为 Debian/Ubuntu 软件包用于各种发行版,例如http://ppa.launchpad.net/chris-lea/node.js/ubuntu

通过在 Heroku 上部署而不需要为 gems 管理操作系统或组件,您可以省去很多麻烦。

【讨论】:

我在共享服务器上没有 sudo 权限,但我设法安装了 node.js 解决了它。我现在正在考虑给 Heroku 一个适当的机会,因为让 Rails 3 站点与资产管道一起工作似乎永无止境的问题。 @Rich,Heroku 绝对是最好的选择。作为开发人员,我发现我不想处理保持服务器正常运行、安全、安装补丁、备份等所需的所有工作。这充其量是耗时的,最坏的情况是非常脆弱。让做得好的专家去做。【参考方案3】:

我在带有 Rails 3.1 的 Dreamhost 上将这些 gem 用于资产管道

group :assets do
  gem 'execjs'
  gem 'therubyracer', :platforms => :ruby
  gem 'johnson'
  gem 'sass-rails', "  ~> 3.1.0"
  gem 'coffee-rails', "~> 3.1.0"
  gem 'uglifier'
end

therubyracer 作为预编译器,johnson 作为运行时。

这适用于 Dreamhost 托管的 2 个 Rails 3.1 应用程序。

【讨论】:

感谢您的评论。您在共享 Dreamhost 服务器或 VPS 上吗?你运行的是哪个版本的 Ruby? 2021年,Rails 4.2.10,这个答案解决了我在Dreamhost共享服务器上的问题【参考方案4】:

您只需要获取libv8,对于带有 Brew 的操作系统即可:

brew install v8

【讨论】:

【参考方案5】:

我在dreamhost共享服务器中。

我在没有使用 root/sudo 的情况下安装了 nodejs。在服务器上:

#download node js (check last version from web)
$ wget http://nodejs.org/dist/v0.8.16/node-v0.8.16-linux-x86.tar.gz
#untar
$ tar xzf node-v0.8.16-linux-x86.tar.gz

最后将其路径添加到 deploy.rb,添加以下行(在这种情况下添加了更多路径):

default_environment["PATH"] = ":/home/myUser/soft/node-v0.8.16-linux-x86/bin:/home/myUser/.gems/bin:/usr/lib/ruby/gems/1.8/bin/:$PATH"

你已经完成了

【讨论】:

在我的例子中,添加到 deploy.rb 的 PATH 很简单:default_environment["PATH"] = "$HOME/local/bin:$PATH" 我正在尝试您的解决方案,但找不到 deploy.rb 文件。我怎样才能找到它?我必须在某个地方创建它吗?【参考方案6】:

我只是看了一个关于这个的介绍。

到目前为止,我一直在使用 ruby​​theracer。显然它不是那么好。而且很大。

但您可以使用任何 javascript 运行时。

另外两个推荐的是execjs和node.js(现在很火)。

确保gem install 选择的gem,然后bundle installbundle update 为您的应用程序。

另一个注意事项是您也应该切换到 1.9.2。 安装RVM (bash https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer)) 你可以同时拥有 1.8.7 和 1.9.2。

【讨论】:

【参考方案7】:

我建议安装 Nodejs。它对我有用。

只需转到您的终端并输入:

sudo apt-get install node.js

输入您的密码...并在要求确认时按“Y”。我希望这会有所帮助!!!

【讨论】:

正如我在 Wolfram 的回答中所说,我在共享服务器上没有 sudo 权限,但这可能对那些有权限的人有用。【参考方案8】:

我刚刚在我的 Win7 开发机器上遇到了同样的问题。看起来像安装https://github.com/hiranpeiris/therubyracer_for_windows 并将gem 'therubyracer' 添加到Gemfile 可以解决问题。

之前:

$ rails generate
c:/Ruby193/lib/ruby/gems/1.9.1/gems/execjs-1.4.0/lib/execjs/runtimes.rb:51:in `autodetect': Could not find a JavaScript runtime. See https://github.com/sstephenson/execjs for a list of available runtimes. (ExecJS::RuntimeUnavailable)
    from c:/Ruby193/lib/ruby/gems/1.9.1/gems/execjs-1.4.0/lib/execjs.rb:5:in `<module:ExecJS>'
(...)

这基本上意味着Rails需要rubyracerlibv8

之后:

$ rails generate
    SECURITY WARNING: No secret option provided to Rack::Session::Cookie.
    This poses a security threat. It is strongly recommended that you
    provide a secret to prevent exploits that may be possible from crafted
    cookies. This will not be supported in future versions of Rack, and
    future versions will even invalidate your existing user cookies.

    Called from: c:/Ruby193/lib/ruby/gems/1.9.1/gems/actionpack-3.2.8/lib/action_dispatch/middleware/session/abstract_store.rb:28:in `initialize'.

Usage: rails generate GENERATOR [args] [options]
(...)

【讨论】:

【参考方案9】:

在 Gemfile 中添加以下 gem 并尝试使用捆绑安装

宝石 "therubyracer", "~> 0.10.2"

【讨论】:

以上是关于Rails:找不到 JavaScript 运行时。有关可用运行时的列表,请参阅 https://github.com/sstephenson/execjs。 (ExecJS::RuntimeUnava的主要内容,如果未能解决你的问题,请参考以下文章

Rails:找不到 JavaScript 运行时。有关可用运行时的列表,请参阅 https://github.com/sstephenson/execjs。 (ExecJS::RuntimeUnava

Gitlab CI 设置错误 - 找不到 JavaScript 运行时

运行 Rails 服务器时出错 - 找不到符号 - therubyracer

无法运行 bootsrap:找不到类型为“application/javascript”的文件“bootstrap-sprockets”

运行任何 rails cmnd 时找不到“activesupport”

Rails 服务器告诉我 --- 找不到类型为 'application/javascript' 的文件 'jquery-ui/datepicker'