为什么gem`therubyracer`默认在Gemfile中注释掉了?

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了为什么gem`therubyracer`默认在Gemfile中注释掉了?相关的知识,希望对你有一定的参考价值。

我创建了一个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>'

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

当我们在启动rails应用程序时首先需要它时,为什么这个gem被注释掉了?

答案

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

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

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

以上是关于为什么gem`therubyracer`默认在Gemfile中注释掉了?的主要内容,如果未能解决你的问题,请参考以下文章

gem 在 OSX 10.15 上安装 therubyracer -v 0.12.3

由于 Mac 上的编译器问题,无法安装 therubyracer gem?

无法在 M1 Macbook Pro 中安装“therubyracer v0.12.3”gem

heroku 上的 therubyracer 错误为“无法通过 Bundler 安装 gems”。

therubyracer gem 安装错误 - mac 10.9

在 OSX 10.11 El Capitan 上安装 therubyracer gem