錯誤訊息
將專案部署到 Ruby 3 版本的 Production 環境時,網頁跑不起來,在 Nginx 的 error log 出現以下錯誤:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
| [ E 2023-03-09 07:36:26.5249 368322/T8 age/Cor/Con/CheckoutSession.cpp:281 ]: [Client 2-12] Cannot checkout session because a spawning error occurred. The identifier of the error is 23a96bb5. Please see earlier logs for details about the error. App 369021 output: Error: The application encountered the following error: You have already activated strscan 3.0.4, but your Gemfile requires strscan 3.0.5. Prepending `bundle exec` to your command may solve this. (Gem::LoadError) App 369021 output: /home/user/.rvm/rubies/ruby-3.1.2/lib/ruby/3.1.0/bundler/runtime.rb:309:in `check_for_activated_spec!' App 369021 output: /home/user/.rvm/rubies/ruby-3.1.2/lib/ruby/3.1.0/bundler/runtime.rb:25:in `block in setup' App 369021 output: /home/user/.rvm/rubies/ruby-3.1.2/lib/ruby/3.1.0/bundler/spec_set.rb:136:in `each' App 369021 output: /home/user/.rvm/rubies/ruby-3.1.2/lib/ruby/3.1.0/bundler/spec_set.rb:136:in `each' App 369021 output: /home/user/.rvm/rubies/ruby-3.1.2/lib/ruby/3.1.0/bundler/runtime.rb:24:in `map' App 369021 output: /home/user/.rvm/rubies/ruby-3.1.2/lib/ruby/3.1.0/bundler/runtime.rb:24:in `setup' App 369021 output: /home/user/.rvm/rubies/ruby-3.1.2/lib/ruby/3.1.0/bundler.rb:151:in `setup' App 369021 output: /home/user/.rvm/rubies/ruby-3.1.2/lib/ruby/3.1.0/bundler/setup.rb:20:in `block in <top (required)>' App 369021 output: /home/user/.rvm/rubies/ruby-3.1.2/lib/ruby/3.1.0/bundler/ui/shell.rb:136:in `with_level' App 369021 output: /home/user/.rvm/rubies/ruby-3.1.2/lib/ruby/3.1.0/bundler/ui/shell.rb:88:in `silence' App 369021 output: /home/user/.rvm/rubies/ruby-3.1.2/lib/ruby/3.1.0/bundler/setup.rb:20:in `<top (required)>' App 369021 output: <internal:/home/user/.rvm/rubies/ruby-3.1.2/lib/ruby/3.1.0/rubygems/core_ext/kernel_require.rb>:85:in `require' App 369021 output: <internal:/home/user/.rvm/rubies/ruby-3.1.2/lib/ruby/3.1.0/rubygems/core_ext/kernel_require.rb>:85:in `require' App 369021 output: /usr/lib/ruby/vendor_ruby/phusion_passenger/loader_shared_helpers.rb:380:in `activate_gem' App 369021 output: /usr/lib/ruby/vendor_ruby/phusion_passenger/loader_shared_helpers.rb:221:in `block in run_load_path_setup_code' App 369021 output: /usr/lib/ruby/vendor_ruby/phusion_passenger/loader_shared_helpers.rb:544:in `running_bundler' App 369021 output: /usr/lib/ruby/vendor_ruby/phusion_passenger/loader_shared_helpers.rb:220:in `run_load_path_setup_code' App 369021 output: /usr/share/passenger/helper-scripts/rack-preloader.rb:91:in `preload_app' App 369021 output: /usr/share/passenger/helper-scripts/rack-preloader.rb:189:in `block in <module:App>' App 369021 output: /usr/lib/ruby/vendor_ruby/phusion_passenger/loader_shared_helpers.rb:397:in `run_block_and_record_step_progress' App 369021 output: /usr/share/passenger/helper-scripts/rack-preloader.rb:188:in `<module:App>' App 369021 output: /usr/share/passenger/helper-scripts/rack-preloader.rb:30:in `<module:PhusionPassenger>' App 369021 output: /usr/share/passenger/helper-scripts/rack-preloader.rb:29:in `<main>' [ E 2023-03-09 07:36:28.4149 368322/T16 age/Cor/App/Implementation.cpp:221 ]: Could not spawn process for application /home/user/project/current: The application encountered the following error: You have already activated strscan 3.0.4, but your Gemfile requires strscan 3.0.5. Prepending `bundle exec` to your command may solve this. (Gem::LoadError) Error ID: 882746cb Error details saved to: /tmp/passenger-error-S5tTKX.html
|
主要的錯誤訊息是這段:
1
| You have already activated strscan 3.0.4, but your Gemfile requires strscan 3.0.5.
|
專案採用了 3.0.5 的版本,系統採用了 3.0.4 的版本,雖然使用了 bundle deployment 但仍然出現套件衝突,而且在本機開發的時候是正常的。
解決方法一:更動系統套件
解決方法一是把系統的版本升上去:
1
| gem install strscan -v 3.0.5
|
解決方法二:更動專案套件
但如果伺服器上有多個專案,例如別的專案使用的和系統一致的 3.0.4 版本,會造成其他專案衝突。所以另一個解決方法是把專案的版本降低為一致的版本,修改專案的 Gemfile 或 Gemfile.lock 再重新部署上去就可以了。當然後反過來也可能會是升級專案或降級系統套件。