[英]Docker compose up fails with `require': cannot load such file — rack/handler/rails (LoadError)
[英]Ruby on Rails: cannot load 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
重新安裝Rails rvm use ruby-2.3.1@rails5.0 --create
后跟gem install rails
。 rails -v
now報告:
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
以刪除所有gems導致:
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
不能加載機架,而是它無法加載機架“一些錯誤的選項”處理程序,因為你的選擇是錯誤的,可能是一個錯字。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.