15

我创建了一个 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: :rubyGemfile.

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

4

1 回答 1

22

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

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

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

于 2013-09-08T19:29:06.460 回答