【问题标题】:Why is the gem `therubyracer` commented out by default in Gemfile?为什么 Gemfile 中的 gem `therubyracer` 默认被注释掉了?
【发布时间】:2013-09-12 07:30:40
【问题描述】:

我创建了一个 rails 应用程序,并尝试启动 rails 服务器。我收到以下错误:

/home/ritesh/.rvm/gems/ruby-1.9.3-p429/gems/execjs-2.0.1/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 /home/ritesh/.rvm/gems/ruby-1.9.3-p429/gems/execjs-2.0.1/lib/execjs.rb:5:in `<module:ExecJS>'
from /home/ritesh/.rvm/gems/ruby-1.9.3-p429/gems/execjs-2.0.1/lib/execjs.rb:4:in `<top (required)>'
from /home/ritesh/.rvm/gems/ruby-1.9.3-p429/gems/uglifier-2.2.1/lib/uglifier.rb:3:in `require'
from /home/ritesh/.rvm/gems/ruby-1.9.3-p429/gems/uglifier-2.2.1/lib/uglifier.rb:3:in `<top (required)>'
from /home/ritesh/.rvm/gems/ruby-1.9.3-p429@global/gems/bundler-1.3.5/lib/bundler/runtime.rb:72:in `require'
from /home/ritesh/.rvm/gems/ruby-1.9.3-p429@global/gems/bundler-1.3.5/lib/bundler/runtime.rb:72:in `block (2 levels) in require'
from /home/ritesh/.rvm/gems/ruby-1.9.3-p429@global/gems/bundler-1.3.5/lib/bundler/runtime.rb:70:in `each'
from /home/ritesh/.rvm/gems/ruby-1.9.3-p429@global/gems/bundler-1.3.5/lib/bundler/runtime.rb:70:in `block in require'
from /home/ritesh/.rvm/gems/ruby-1.9.3-p429@global/gems/bundler-1.3.5/lib/bundler/runtime.rb:59:in `each'
from /home/ritesh/.rvm/gems/ruby-1.9.3-p429@global/gems/bundler-1.3.5/lib/bundler/runtime.rb:59:in `require'
from /home/ritesh/.rvm/gems/ruby-1.9.3-p429@global/gems/bundler-1.3.5/lib/bundler.rb:132:in `require'
from /home/ritesh/projects/interview/config/application.rb:7:in `<top (required)>'
from /home/ritesh/.rvm/gems/ruby-1.9.3-p429/gems/railties-4.0.0/lib/rails/commands.rb:76:in `require'
from /home/ritesh/.rvm/gems/ruby-1.9.3-p429/gems/railties-4.0.0/lib/rails/commands.rb:76:in `block in <top (required)>'
from /home/ritesh/.rvm/gems/ruby-1.9.3-p429/gems/railties-4.0.0/lib/rails/commands.rb:73:in `tap'
from /home/ritesh/.rvm/gems/ruby-1.9.3-p429/gems/railties-4.0.0/lib/rails/commands.rb:73:in `<top (required)>'
from bin/rails:4:in `require'
from bin/rails:4:in `<main>'

虽然我能够通过从Gemfile 中删除gem 'therubyracer', platforms: :ruby 行之前的注释来修复它。

为什么我们在启动 Rails 应用程序时首先需要它时将它注释掉?

【问题讨论】:

  • 非常好的问题,此外,在 rails > 4.0 中,错误消息也没有帮助。 There was an error while trying to load the gem 'uglifier'. (Bundler::GemRequireError)

标签: ruby-on-rails ruby-on-rails-4 rubygems


【解决方案1】:

因为如果机器上安装了另一个 JavaScript 运行时(如 Node.js),Rails 可以使用它,并且不需要 ruby​​racer。

Rails 使用 ExecJS 加载 JavaScript 运行时。有关 ExecJS 的更多信息,请参阅其 Github 页面:https://github.com/sstephenson/execjs。自述文件提供了可用运行时列表(如您的错误日志注释)。

根据您的部署过程和生产环境,您使用哪种 JavaScript 运行时可能并不重要。有些人对 therubyracer 库的大小有疑问(请参阅Rails - Could not find a JavaScript runtime?),将它安装在生产服务器上可能并不明智。

【讨论】:

  • 是否有相关文档说明何时应该在生产中避免使用 therubyracer? IE。在什么流量,内存限制等下。
  • 我通过 nvm 设置了 Node 环境,但 Rails 仍然因那个神秘错误而失败。我花了一些时间才意识到我需要取消注释该行...我认为 Rails 默认更好的选择是选择退出而不是选择加入。
  • 对此的任何更新我试图弄清楚为什么 jquery 在升级到 Ubuntu 20.04 后停止工作我没有收到任何错误,除了由于 .scss 文件中所有 @ 语句的错误选择器而忽略的规则集
猜你喜欢
  • 1970-01-01
  • 2014-08-05
  • 2013-04-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-09-09
  • 2018-03-10
相关资源
最近更新 更多