Ruby on Rails:无法加载rack / handler /
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Ruby on Rails:无法加载rack / handler /相关的知识,希望对你有一定的参考价值。
昨晚我有一个完全工作的Rails服务器。但是,在今天早上访问我的电脑时,我发现它已经崩溃了。我启动了备份,然后SSH连接到我的远程服务器,并尝试重新启动服务器进程,首先查询:
rails server -h
结果导致:
/usr/local/lib/site_ruby/2.3.0/rubygems.rb:270:in `find_spec_for_exe': can't find gem railties (>= 0.a) (Gem::GemNotFoundException)
from /usr/local/lib/site_ruby/2.3.0/rubygems.rb:298:in `activate_bin_path'
from /usr/local/bin/rails:22:in `<main>'
然后我尝试了一个bundle install
,它抛出了以下错误:
enter code here/usr/local/lib/site_ruby/2.3.0/rubygems.rb:270:in `find_spec_for_exe': can't find gem bundler (>= 0.a) (Gem::GemNotFoundException)
from /usr/local/lib/site_ruby/2.3.0/rubygems.rb:298:in `activate_bin_path'
from /usr/local/bin/bundle:22:in `<main>'
然后我用rvm use ruby-2.3.1@rails5.0 --create
和gem install rails
重新安装了Rails。 rails -v
现在报道:
Rails 5.0.1
但是,当我尝试启动服务器进程(rails server -p 80 - b 139.162.246.138
)时,我得到:
Exiting
/home/peter/.rvm/gems/ruby-2.3.1@rails5.0/gems/rack-2.0.1/lib/rack/handler.rb:74:in `require': cannot load such file -- rack/handler/- (LoadError)
from /home/peter/.rvm/gems/ruby-2.3.1@rails5.0/gems/rack-2.0.1/lib/rack/handler.rb:74:in `try_require'
from /home/peter/.rvm/gems/ruby-2.3.1@rails5.0/gems/rack-2.0.1/lib/rack/handler.rb:16:in `get'
from /home/peter/.rvm/gems/ruby-2.3.1@rails5.0/gems/rack-2.0.1/lib/rack/server.rb:300:in `server'
from /home/peter/.rvm/gems/ruby-2.3.1@rails5.0/gems/railties-5.0.1/lib/rails/commands/server.rb:112:in `print_boot_information'
from /home/peter/.rvm/gems/ruby-2.3.1@rails5.0/gems/railties-5.0.1/lib/rails/commands/server.rb:73:in `start'
from /home/peter/.rvm/gems/ruby-2.3.1@rails5.0/gems/railties-5.0.1/lib/rails/commands/commands_tasks.rb:90:in `block in server'
from /home/peter/.rvm/gems/ruby-2.3.1@rails5.0/gems/railties-5.0.1/lib/rails/commands/commands_tasks.rb:85:in `tap'
from /home/peter/.rvm/gems/ruby-2.3.1@rails5.0/gems/railties-5.0.1/lib/rails/commands/commands_tasks.rb:85:in `server'
from /home/peter/.rvm/gems/ruby-2.3.1@rails5.0/gems/railties-5.0.1/lib/rails/commands/commands_tasks.rb:49:in `run_command!'
from /home/peter/.rvm/gems/ruby-2.3.1@rails5.0/gems/railties-5.0.1/lib/rails/commands.rb:18:in `<top (required)>'
from bin/rails:4:in `require'
from bin/rails:4:in `<main>'
我尝试卸载并重新安装ruby和rails,并运行新的bundle install
。没有得到基本相同的错误:
/home/peter/.rvm/gems/ruby-2.4.0-rc1/gems/activesupport-5.0.1/lib/active_support/xml_mini.rb:51: warning: constant ::Fixnum is deprecated
/home/peter/.rvm/gems/ruby-2.4.0-rc1/gems/activesupport-5.0.1/lib/active_support/xml_mini.rb:52: warning: constant ::Bignum is deprecated
Exiting
/home/peter/.rvm/gems/ruby-2.4.0-rc1/gems/rack-2.0.1/lib/rack/handler.rb:74:in `require': cannot load such file -- rack/handler/- (LoadError)
from /home/peter/.rvm/gems/ruby-2.4.0-rc1/gems/rack-2.0.1/lib/rack/handler.rb:74:in `try_require'
from /home/peter/.rvm/gems/ruby-2.4.0-rc1/gems/rack-2.0.1/lib/rack/handler.rb:16:in `get'
from /home/peter/.rvm/gems/ruby-2.4.0-rc1/gems/rack-2.0.1/lib/rack/server.rb:300:in `server'
from /home/peter/.rvm/gems/ruby-2.4.0-rc1/gems/railties-5.0.1/lib/rails/commands/server.rb:112:in `print_boot_information'
from /home/peter/.rvm/gems/ruby-2.4.0-rc1/gems/railties-5.0.1/lib/rails/commands/server.rb:73:in `start'
from /home/peter/.rvm/gems/ruby-2.4.0-rc1/gems/railties-5.0.1/lib/rails/commands/commands_tasks.rb:90:in `block in server'
from /home/peter/.rvm/gems/ruby-2.4.0-rc1/gems/railties-5.0.1/lib/rails/commands/commands_tasks.rb:85:in `tap'
from /home/peter/.rvm/gems/ruby-2.4.0-rc1/gems/railties-5.0.1/lib/rails/commands/commands_tasks.rb:85:in `server'
from /home/peter/.rvm/gems/ruby-2.4.0-rc1/gems/railties-5.0.1/lib/rails/commands/commands_tasks.rb:49:in `run_command!'
from /home/peter/.rvm/gems/ruby-2.4.0-rc1/gems/railties-5.0.1/lib/rails/commands.rb:18:in `<top (required)>'
from bin/rails:4:in `require'
from bin/rails:4:in `<main>'
我还尝试完全卸载rails和railties:
gem uninstall rails -v 5.0.1
gem uninstall railties -v 5.0.1
gem install rails -v 5.0.1
gen install railties -v 5.0.1
同样的错误。
尝试使用以下命令查找问题:
sudo grep -rnw './' -e "/var/lib/gems/2.3.0/"
从源目录输出到控制台。
尝试访问错误消息中列出的目录会导致:
cd /var/lib/gems/
-bash: /home/peter/.rvm/scripts/initialize: No such file or directory
-bash: /home/peter/.rvm/scripts/hook: No such file or directory
运行sudo gem uninstall --all
以删除所有宝石会导致:
You have requested to uninstall the gem:
actioncable-5.0.1
rails-5.0.1 depends on actioncable (= 5.0.1)
If you remove this gem, these dependencies will not be met.
Continue with Uninstall? [yN] ERROR: While executing gem ... (Gem::DependencyRemovalException)
Uninstallation aborted due to dependent gem(s)
虽然在运行命令之前删除rails-5.0.1 gem修复了这个...但是,在运行这个应该删除所有gem的命令之后,rails -v
现在输出:
Rails 4.2.7.1
并运行gem uninstall rails-4.2.7.1
不会删除此版本。
gem uninstall -v rails-4.2.7.1
导致:
ERROR: While executing gem ... (Gem::Requirement::BadRequirementError)
Illformed requirement ["rails-4.2.7.1"]
更新:最终设法删除rails和ruby。重新安装它们。同样的问题。
尝试创建一个重新启动项目和新项目完全相同的事情。
完成所有工作后,解决方案很简单。我在打字:
rails server -p 80 - b 139.162.246.138
代替:
rails server -p 80 -b 139.162.246.138
你使用=> rbenv安装宝石后重新开始吗?如果没有检查=> gemfile以确保你有匹配的ruby版本以及你的=> gemfile.lock(在你工作的目录中)
这个故事的寓意是,如果你在调用rails服务器时在命令行上乱码,你会得到:
bootsnap-1.3.2/lib/bootsnap/load_path_cache/
core_ext/kernel_require.rb:32:in `require': cannot
load such file -- rack/handler/--some-wrong-option (LoadError)
这有点模棱两可。这不是bootsnap
无法加载机架,它是无法加载机架“一些错误的选项”处理程序,因为你的选项是错误的,可能是一个错字。
以上是关于Ruby on Rails:无法加载rack / handler /的主要内容,如果未能解决你的问题,请参考以下文章
Ruby on Rails“由于bot而导致的UTF-8中无效的字节序列”
在 Ruby on Rails 的上下文中引用时,啥是中间件?
Ruby on Rails 部署到阿里巴巴 ECS 后无法加载