如何避免 bootsnap 和 railties 导致此错误?

How do I avoid bootsnap and railties to cause this error?

----更新

我已经将 repo 克隆到另一个目录并再次抛出所有进程,虽然我注意到这个问题只有在使用后才会出现:

bundle install --deployment --without development test

如果我只使用 bundle install 我可以 rails c 没有问题。

为什么会这样?使用标志很重要吗?我这样做只是因为在 guide on how to deploy Rails app

----更新

我正在尝试在 Ubuntu 上部署一个 ruby 应用程序。我在错误的位置 rails c 正确地获得了 运行 一次相同的回购。 然后我在正确的位置 (var/www/app/code) 执行了所有相同的步骤,但是当我 运行 rails c 我 运行 遇到这个问题时:

user@cardano-db-sync:/var/www/swan/code$ rails c                                                                                                      
Traceback (most recent call last):                                                                                                                                                           
        80: from bin/rails:9:in `<main>'                                                                                                                                                     
        79: from /var/www/swan/code/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.7.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
        78: from /var/www/swan/code/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.7.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
        77: from /var/www/swan/code/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.7.3/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
        76: from /var/www/swan/code/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.7.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
        75: from /var/www/swan/code/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.7.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'                  
        74: from /var/www/swan/code/vendor/bundle/ruby/2.6.0/gems/railties-6.1.3.1/lib/rails/commands.rb:18:in `<main>'                                
        73: from /var/www/swan/code/vendor/bundle/ruby/2.6.0/gems/railties-6.1.3.1/lib/rails/command.rb:50:in `invoke'                                                             
        72: from /var/www/swan/code/vendor/bundle/ruby/2.6.0/gems/railties-6.1.3.1/lib/rails/command/base.rb:69:in `perform'                                                        
        71: from /var/www/swan/code/vendor/bundle/ruby/2.6.0/gems/thor-1.1.0/lib/thor.rb:392:in `dispatch'
        72: from /var/www/swan/code/vendor/bundle/ruby/2.6.0/gems/railties-6.1.3.1/lib/rails/command/base.rb:69:in `perform'                                                         [0/1955]
        71: from /var/www/swan/code/vendor/bundle/ruby/2.6.0/gems/thor-1.1.0/lib/thor.rb:392:in `dispatch'                                                                                   
        70: from /var/www/swan/code/vendor/bundle/ruby/2.6.0/gems/thor-1.1.0/lib/thor/invocation.rb:127:in `invoke_command'                                                                  
        69: from /var/www/swan/code/vendor/bundle/ruby/2.6.0/gems/thor-1.1.0/lib/thor/command.rb:27:in `run'                                                                                 
        68: from /var/www/swan/code/vendor/bundle/ruby/2.6.0/gems/railties-6.1.3.1/lib/rails/commands/console/console_command.rb:101:in `perform'                                            
        67: from /var/www/swan/code/vendor/bundle/ruby/2.6.0/gems/railties-6.1.3.1/lib/rails/command/actions.rb:15:in `require_application_and_environment!'                                 
        66: from /var/www/swan/code/vendor/bundle/ruby/2.6.0/gems/railties-6.1.3.1/lib/rails/command/actions.rb:28:in `require_environment!'                                                 
        65: from /var/www/swan/code/vendor/bundle/ruby/2.6.0/gems/railties-6.1.3.1/lib/rails/application.rb:360:in `require_environment!'                                                    
        64: from /var/www/swan/code/vendor/bundle/ruby/2.6.0/gems/activesupport-6.1.3.1/lib/active_support/dependencies.rb:332:in `require'                                                  
        63: from /var/www/swan/code/vendor/bundle/ruby/2.6.0/gems/activesupport-6.1.3.1/lib/active_support/dependencies.rb:299:in `load_dependency'                                          
        62: from /var/www/swan/code/vendor/bundle/ruby/2.6.0/gems/activesupport-6.1.3.1/lib/active_support/dependencies.rb:332:in `block in require'                                         
        61: from /var/www/swan/code/vendor/bundle/ruby/2.6.0/gems/zeitwerk-2.4.2/lib/zeitwerk/kernel.rb:34:in `require'                                                                      
        60: from /var/www/swan/code/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.7.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'                                     
        59: from /var/www/swan/code/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.7.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'                   
        58: from /var/www/swan/code/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.7.3/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'                                      
        57: from /var/www/swan/code/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.7.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'          
        56: from /var/www/swan/code/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.7.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'                                     
        55: from /var/www/swan/code/config/environment.rb:5:in `<main>'                       
        54: from /var/www/swan/code/vendor/bundle/ruby/2.6.0/gems/railties-6.1.3.1/lib/rails/application.rb:384:in `initialize!'                                                             
        53: from /var/www/swan/code/vendor/bundle/ruby/2.6.0/gems/railties-6.1.3.1/lib/rails/initializable.rb:60:in `run_initializers'                                                       
        52: from /home/user/.rvm/rubies/ruby-2.6.1/lib/ruby/2.6.0/tsort.rb:205:in `tsort_each'                                                                                             
        51: from /home/user/.rvm/rubies/ruby-2.6.1/lib/ruby/2.6.0/tsort.rb:226:in `tsort_each'                                                                                             
        50: from /home/user/.rvm/rubies/ruby-2.6.1/lib/ruby/2.6.0/tsort.rb:347:in `each_strongly_connected_component'                                                                      
        49: from /home/user/.rvm/rubies/ruby-2.6.1/lib/ruby/2.6.0/tsort.rb:347:in `call'    
        48: from /home/user/.rvm/rubies/ruby-2.6.1/lib/ruby/2.6.0/tsort.rb:347:in `each'    
        47: from /home/user/.rvm/rubies/ruby-2.6.1/lib/ruby/2.6.0/tsort.rb:349:in `block in each_strongly_connected_component'                                                             
        46: from /home/user/.rvm/rubies/ruby-2.6.1/lib/ruby/2.6.0/tsort.rb:415:in `each_strongly_connected_component_from'                                                                 
        45: from /home/user/.rvm/rubies/ruby-2.6.1/lib/ruby/2.6.0/tsort.rb:415:in `call'    
        44: from /var/www/swan/code/vendor/bundle/ruby/2.6.0/gems/railties-6.1.3.1/lib/rails/initializable.rb:50:in `tsort_each_child'                                                       
        43: from /var/www/swan/code/vendor/bundle/ruby/2.6.0/gems/railties-6.1.3.1/lib/rails/initializable.rb:50:in `each'                                                                   
        42: from /home/user/.rvm/rubies/ruby-2.6.1/lib/ruby/2.6.0/tsort.rb:421:in `block in each_strongly_connected_component_from'                                                        
        41: from /home/user/.rvm/rubies/ruby-2.6.1/lib/ruby/2.6.0/tsort.rb:431:in `each_strongly_connected_component_from'                                                                 
        40: from /home/user/.rvm/rubies/ruby-2.6.1/lib/ruby/2.6.0/tsort.rb:422:in `block (2 levels) in each_strongly_connected_component_from'                                             
        39: from /home/user/.rvm/rubies/ruby-2.6.1/lib/ruby/2.6.0/tsort.rb:350:in `block (2 levels) in each_strongly_connected_component'                                                  
        38: from /home/user/.rvm/rubies/ruby-2.6.1/lib/ruby/2.6.0/tsort.rb:228:in `block in tsort_each'                                                                                    
        37: from /var/www/swan/code/vendor/bundle/ruby/2.6.0/gems/railties-6.1.3.1/lib/rails/initializable.rb:61:in `block in run_initializers'                                              
        36: from /var/www/swan/code/vendor/bundle/ruby/2.6.0/gems/railties-6.1.3.1/lib/rails/initializable.rb:32:in `run'                                                                    
        35: from /var/www/swan/code/vendor/bundle/ruby/2.6.0/gems/railties-6.1.3.1/lib/rails/initializable.rb:32:in `instance_exec'                                                          
        34: from /var/www/swan/code/vendor/bundle/ruby/2.6.0/gems/railties-6.1.3.1/lib/rails/engine.rb:570:in `block in <class:Engine>'                                                      
        33: from /var/www/swan/code/vendor/bundle/ruby/2.6.0/gems/railties-6.1.3.1/lib/rails/engine.rb:570:in `each'                                                                         
        32: from /var/www/swan/code/vendor/bundle/ruby/2.6.0/gems/railties-6.1.3.1/lib/rails/engine.rb:571:in `block (2 levels) in <class:Engine>'                                           
        31: from /var/www/swan/code/vendor/bundle/ruby/2.6.0/gems/activesupport-6.1.3.1/lib/active_support/dependencies.rb:332:in `require'                                                  
        30: from /var/www/swan/code/vendor/bundle/ruby/2.6.0/gems/activesupport-6.1.3.1/lib/active_support/dependencies.rb:299:in `load_dependency'                                          
        29: from /var/www/swan/code/vendor/bundle/ruby/2.6.0/gems/activesupport-6.1.3.1/lib/active_support/dependencies.rb:332:in `block in require'                                         
        28: from /var/www/swan/code/vendor/bundle/ruby/2.6.0/gems/zeitwerk-2.4.2/lib/zeitwerk/kernel.rb:34:in `require'                                                                      
        27: from /var/www/swan/code/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.7.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'                                     
        26: from /var/www/swan/code/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.7.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'                   
        25: from /var/www/swan/code/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.7.3/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'                                      
        24: from /var/www/swan/code/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.7.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'          
        23: from /var/www/swan/code/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.7.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'                                     
        22: from /var/www/swan/code/config/environments/development.rb:1:in `<main>'          
        21: from /var/www/swan/code/vendor/bundle/ruby/2.6.0/gems/railties-6.1.3.1/lib/rails/railtie.rb:234:in `configure'                                                                   
        20: from /var/www/swan/code/vendor/bundle/ruby/2.6.0/gems/railties-6.1.3.1/lib/rails/railtie.rb:234:in `instance_eval'                                                               
        19: from /var/www/swan/code/config/environments/development.rb:51:in `block in <main>'                                                                                               
        18: from /var/www/swan/code/vendor/bundle/ruby/2.6.0/gems/activesupport-6.1.3.1/lib/active_support/dependencies.rb:332:in `require'                                                  
        17: from /var/www/swan/code/vendor/bundle/ruby/2.6.0/gems/activesupport-6.1.3.1/lib/active_support/dependencies.rb:299:in `load_dependency'                                          
        16: from /var/www/swan/code/vendor/bundle/ruby/2.6.0/gems/activesupport-6.1.3.1/lib/active_support/dependencies.rb:332:in `block in require'                                         
        15: from /var/www/swan/code/vendor/bundle/ruby/2.6.0/gems/zeitwerk-2.4.2/lib/zeitwerk/kernel.rb:34:in `require'                                                                      
        14: from /var/www/swan/code/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.7.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'                                     
        13: from /var/www/swan/code/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.7.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'                   
        12: from /var/www/swan/code/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.7.3/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'                                      
        11: from /var/www/swan/code/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.7.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'          
        10: from /var/www/swan/code/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.7.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
         9: from /var/www/swan/code/vendor/bundle/ruby/2.6.0/gems/activesupport-6.1.3.1/lib/active_support/evented_file_update_checker.rb:6:in `<main>'                                      
         8: from /var/www/swan/code/vendor/bundle/ruby/2.6.0/gems/activesupport-6.1.3.1/lib/active_support/dependencies.rb:332:in `require'                                                  
         7: from /var/www/swan/code/vendor/bundle/ruby/2.6.0/gems/activesupport-6.1.3.1/lib/active_support/dependencies.rb:299:in `load_dependency'     
         6: from /var/www/swan/code/vendor/bundle/ruby/2.6.0/gems/activesupport-6.1.3.1/lib/active_support/dependencies.rb:332:in `block in require'                      
         5: from /var/www/swan/code/vendor/bundle/ruby/2.6.0/gems/zeitwerk-2.4.2/lib/zeitwerk/kernel.rb:34:in `require'                                
         4: from /var/www/swan/code/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.7.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:44:in `require'                           
         3: from /var/www/swan/code/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.7.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
         2: from /var/www/swan/code/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.7.3/lib/bootsnap/load_path_cache/loaded_features_index.rb:89:in `register'
         1: from /var/www/swan/code/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.7.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
/var/www/swan/code/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.7.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require': cannot load such file -- listen (LoadError)

bundle install 使用了很多 gem install .. 但仍然无法找出问题所在..我也在使用 rvm use 2.6.1 所以我不明白为什么 ruby/2.6.0出现在那里。

无论如何这是我的 gemfile:

source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }

ruby '2.6.1'

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 6.1.3'
# Use postgresql as the database for Active Record
gem 'pg', '>= 0.18', '< 2.0'
# Use Puma as the app server
gem 'puma', '~> 4.1'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
# gem 'jbuilder', '~> 2.7'
# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 4.0'
# Use Active Model has_secure_password
gem 'bcrypt', '~> 3.1.7'

# Use Active Storage variant
# gem 'image_processing', '~> 1.2'

# Reduces boot times through caching; required in config/boot.rb
gem 'bootsnap', require: false

gem 'mimemagic', github: 'mimemagicrb/mimemagic', ref: '01f92d86d15d85cfd0f20dabd025dcbd36a8a60f'

# Use Rack CORS for handling Cross-Origin Resource Sharing (CORS), making cross-origin AJAX possible
gem 'rack-cors'

gem 'jsonapi-serializer'

gem 'jwt'

group :development, :test do
  # Call 'byebug' anywhere in the code to stop execution and get a debugger console
  gem 'seed_dump'
  gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
  gem 'pry'
end

group :development do
  gem 'listen', '~> 3.2'
  # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
  gem 'spring'
  gem 'spring-watcher-listen', '~> 2.0.0'
  gem 'rails-erd'
end

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]

你的错误在最后一行;

/var/www/swan/code/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.7.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require': cannot load such file -- listen (LoadError)

bundle install --deployment --without development test 命令仅安装生产和一般 gems。不安装开发或测试 gems。 Rails读取环境变量RAILS_ENV设置环境。 RAILS_ENV 变量如果没有设置 rails 默认接受开发。并且捆绑器尝试加载所有 gems + 开发组 gems。但是 bundle install --deployment --without development test 命令只安装生产和一般 gems。所以没有安装 listen gem 因为 listen gem 在开发组。 RAILS_ENV=production bin/rails c 命令未抛出错误,因为未尝试加载开发 gems.