Search code examples
ruby-on-railseager-loadinggemfile

Rails 5: rails s production with config.eager_load=true fails while gem 'gem_name', require: false


I've been struggling to deploy an application in production with config.eager_load = true.

I know this configuration loads most of Rails and application code in memory, and it's a nice feature to have in production(like) environments, the problem is that i have a custom rails engine with some code that is used only on certain modules of my main application code and it's only required on certain files.

My custom engine is installed like this in Gemfile:

gem 'gem_name', require: false

and required in files like this:

require 'gem_name'

So, when i run rails s -e production (which has config.eager_load=true activated) it fails automatically with the following error

bootsnap/load_path_cache/core_ext/kernel_require.rb:58:in `load': No such file to load (LoadError)

Any ideas on how to make eager_load work when a gem is not required on Gemfile?

gem 'gem_name', require: false

And what problems could i have if i set eager_load to false on production(like) environments?


Solution

  • I researched for a bit, try upating bootsnap gem, try delete 'bootsnap-load-path-cache' and 'bootsnap-compile-cache' from tmp/cache folder. This article May help understand eager load https://blog.arkency.com/2014/11/dont-forget-about-eager-load-when-extending-autoload/

    This topic may help understand What's the impact of eager_load=true?

    it points to other solution, not require but autoload(http://www.rubyinside.com/ruby-techniques-revealed-autoload-1652.html)

    From the guides(please read): https://guides.rubyonrails.org/autoloading_and_reloading_constants.html#autoload-paths-and-eager-load-paths