因为’uglifier’而无法启动Ruby-on-rails Web应用程序

尝试加载gem’ugllifier’时出错。

Gem Load Error is: wrong argument type Class (expected Module) Backtrace for gem load error is: /usr/local/lib/ruby/gems/2.4.0/gems/therubyracer-0.12.2/lib/v8/conversion.rb:23:in `include' /usr/local/lib/ruby/gems/2.4.0/gems/therubyracer-0.12.2/lib/v8/conversion.rb:23:in `block (2 levels) in ' /usr/local/lib/ruby/gems/2.4.0/gems/therubyracer-0.12.2/lib/v8/conversion.rb:22:in `class_eval' /usr/local/lib/ruby/gems/2.4.0/gems/therubyracer-0.12.2/lib/v8/conversion.rb:22:in `block in ' /usr/local/lib/ruby/gems/2.4.0/gems/therubyracer-0.12.2/lib/v8/conversion.rb:21:in `each' /usr/local/lib/ruby/gems/2.4.0/gems/therubyracer-0.12.2/lib/v8/conversion.rb:21:in `' /usr/local/lib/ruby/gems/2.4.0/gems/therubyracer-0.12.2/lib/v8.rb:22:in `require' /usr/local/lib/ruby/gems/2.4.0/gems/therubyracer-0.12.2/lib/v8.rb:22:in `' /usr/local/lib/ruby/gems/2.4.0/gems/execjs-2.7.0/lib/execjs/ruby_racer_runtime.rb:108:in `require' /usr/local/lib/ruby/gems/2.4.0/gems/execjs-2.7.0/lib/execjs/ruby_racer_runtime.rb:108:in `available?' /usr/local/lib/ruby/gems/2.4.0/gems/execjs-2.7.0/lib/execjs/runtimes.rb:63:in `each' /usr/local/lib/ruby/gems/2.4.0/gems/execjs-2.7.0/lib/execjs/runtimes.rb:63:in `find' /usr/local/lib/ruby/gems/2.4.0/gems/execjs-2.7.0/lib/execjs/runtimes.rb:63:in `best_available' /usr/local/lib/ruby/gems/2.4.0/gems/execjs-2.7.0/lib/execjs/runtimes.rb:57:in `autodetect' /usr/local/lib/ruby/gems/2.4.0/gems/execjs-2.7.0/lib/execjs.rb:5:in `' /usr/local/lib/ruby/gems/2.4.0/gems/execjs-2.7.0/lib/execjs.rb:4:in `' /usr/local/lib/ruby/gems/2.4.0/gems/uglifier-3.0.4/lib/uglifier.rb:5:in `require' /usr/local/lib/ruby/gems/2.4.0/gems/uglifier-3.0.4/lib/uglifier.rb:5:in `' /usr/local/lib/ruby/gems/2.4.0/gems/bundler-1.13.7/lib/bundler/runtime.rb:91:in `require' /usr/local/lib/ruby/gems/2.4.0/gems/bundler-1.13.7/lib/bundler/runtime.rb:91:in `block (2 levels) in require' /usr/local/lib/ruby/gems/2.4.0/gems/bundler-1.13.7/lib/bundler/runtime.rb:86:in `each' /usr/local/lib/ruby/gems/2.4.0/gems/bundler-1.13.7/lib/bundler/runtime.rb:86:in `block in require' /usr/local/lib/ruby/gems/2.4.0/gems/bundler-1.13.7/lib/bundler/runtime.rb:75:in `each' /usr/local/lib/ruby/gems/2.4.0/gems/bundler-1.13.7/lib/bundler/runtime.rb:75:in `require' /usr/local/lib/ruby/gems/2.4.0/gems/bundler-1.13.7/lib/bundler.rb:106:in `require' /var/www/geia.junyuzhu.com/public_html/testapp/config/application.rb:7:in `' /var/www/geia.junyuzhu.com/public_html/testapp/config/environment.rb:2:in `require_relative' /var/www/geia.junyuzhu.com/public_html/testapp/config/environment.rb:2:in `' config.ru:3:in `require_relative' config.ru:3:in `block in ' /usr/local/lib/ruby/gems/2.4.0/gems/rack-2.0.1/lib/rack/builder.rb:55:in `instance_eval' /usr/local/lib/ruby/gems/2.4.0/gems/rack-2.0.1/lib/rack/builder.rb:55:in `initialize' config.ru:1:in `new' config.ru:1:in `' /usr/share/passenger/helper-scripts/rack-preloader.rb:110:in `eval' /usr/share/passenger/helper-scripts/rack-preloader.rb:110:in `preload_app' /usr/share/passenger/helper-scripts/rack-preloader.rb:156:in `' /usr/share/passenger/helper-scripts/rack-preloader.rb:30:in `' /usr/share/passenger/helper-scripts/rack-preloader.rb:29:in `' Bundler Error Backtrace: (Bundler::GemRequireError) /usr/local/lib/ruby/gems/2.4.0/gems/bundler-1.13.7/lib/bundler/runtime.rb:94:in `rescue in block (2 levels) in require' /usr/local/lib/ruby/gems/2.4.0/gems/bundler-1.13.7/lib/bundler/runtime.rb:90:in `block (2 levels) in require' /usr/local/lib/ruby/gems/2.4.0/gems/bundler-1.13.7/lib/bundler/runtime.rb:86:in `each' /usr/local/lib/ruby/gems/2.4.0/gems/bundler-1.13.7/lib/bundler/runtime.rb:86:in `block in require' /usr/local/lib/ruby/gems/2.4.0/gems/bundler-1.13.7/lib/bundler/runtime.rb:75:in `each' /usr/local/lib/ruby/gems/2.4.0/gems/bundler-1.13.7/lib/bundler/runtime.rb:75:in `require' /usr/local/lib/ruby/gems/2.4.0/gems/bundler-1.13.7/lib/bundler.rb:106:in `require' /var/www/geia.junyuzhu.com/public_html/testapp/config/application.rb:7:in `' /var/www/geia.junyuzhu.com/public_html/testapp/config/environment.rb:2:in `require_relative' /var/www/geia.junyuzhu.com/public_html/testapp/config/environment.rb:2:in `' config.ru:3:in `require_relative' config.ru:3:in `block in ' /usr/local/lib/ruby/gems/2.4.0/gems/rack-2.0.1/lib/rack/builder.rb:55:in `instance_eval' /usr/local/lib/ruby/gems/2.4.0/gems/rack-2.0.1/lib/rack/builder.rb:55:in `initialize' config.ru:1:in `new' config.ru:1:in `' /usr/share/passenger/helper-scripts/rack-preloader.rb:110:in `eval' /usr/share/passenger/helper-scripts/rack-preloader.rb:110:in `preload_app' /usr/share/passenger/helper-scripts/rack-preloader.rb:156:in `' /usr/share/passenger/helper-scripts/rack-preloader.rb:30:in `' /usr/share/passenger/helper-scripts/rack-preloader.rb:29:in `' 

我试图安装nodejs并重启apache服务器。 它对这个问题没有帮助。

bundle show uglifier给出

 /usr/local/lib/ruby/gems/2.4.0/gems/uglifier-3.0.4 

我假设我正确安装了uglifier。

还有gem 'therubyracer', platforms: :ruby在Gemfile中没有注释。

请帮忙,我不知道如何解决这个问题。

这是therubyracer和Ruby 2.4 的已知问题 。 Ruby 2.4兼容性存在一些其他问题,这些问题可通过https://github.com/cowboyd/therubyracer/issues/430在其问题跟踪器中进行跟踪。

您应该使用早期版本的Ruby,例如2.3.3,直到新版本发布了therubyracer。

BTW:有几个gem与Ruby 2.4不兼容。 为了防止您在新版本发布后遇到大量兼容性问题,在发布的第一天不升级可能是明智之举

在默认的rails Gemfile ,gem therubyracer的行被注释掉了。 如果你取消注释它,你将得到那个gem,它应该工作。 (为我解决了问题)

要么

运行以下推荐

 sudo apt-get install nodejs 

Uglifier是一个JS包装器,它需要运行JS运行时或JS解释器