spree-contrib/spree_i18n

Zeitwerk::NameError when deploying heroku

Closed this issue Β· 6 comments

Hi.

I am using ruby 2.5.1 and Rails 6.0.1. Spree version 4.0.2. I added spree_i18n to my gem file gem 'spree_i18n', github: 'spree-contrib/spree_i18n'. In development there was no problem but while i am deploying the app to heroku I faced with that error

Zeitwerk::NameError: expected file /tmp/build_7b375389a4acf180984d2e3637e31253/vendor/bundle/ruby/2.5.0/bundler/gems/spree_i18n-b230796ed58c/app/controllers/spree/base_controller_decorator.rb to define constant Spree::BaseControllerDecorator, but didn't

Why? Could you help me?

Cheers

i have the same problem.. please help

Hi @enderahmetyurt
I got a similar problem in another project, and I solved the problem by downgrading the loader from Zeitwerk to the previous one.
you can do that by updating your config/application.rb

    # config.load_defaults 6.0
    config.autoload = :classic

Autoloading during initialization is going
to be an error condition in future versions of Rails.

Reloading does not reboot the application, and therefore code executed during
initialization does not run again. So, if you reload Spree::Preferences, for example,
the expected changes won't be reflected in that stale Module object.

Setting config.autoload = :classic is probably not a good medium term solution.
Is there a work around where we can still use zeitwerk?

I experienced this same issue when deploying a Rails 6.0.2 application to an Ubuntu 18.04 server. I found out that the issue was with zeitwerk. Zeitwerk is the new code loader engine used in Rails 6. It’s meant to be the new default for all Rails 6+ projects replacing the old classic engine. Zeitwerk provides the features of code autoloading, eager loading, and reloading.

Here's how I solved it:

Navigate to the config/application.rb file on your project.

Add this line within your application module to switch to classic mode for autoloading:

config.autoloader = :classic

You can see more details here: Rails 6 with zeitwerk doesn't load class from module

I have a silly answer, but I was facing the same issue and this solved it for me, my file name was different (i left out one letter) from my class name.

Maybe check for such an error in your code before getting too stressed.

Hi @enderahmetyurt
I got a similar problem in another project, and I solved the problem by downgrading the loader from Zeitwerk to the previous one.
you can do that by updating your config/application.rb

    # config.load_defaults 6.0
    config.autoload = :classic

is

config.autoloader = :classic