I recently upgraded my rails application to rails 7 and after upgrading when I try to call the call from the lib folder I am getting this error NameError (uninitialized constant Error)
I have following file structure in the lib folder
lib
-> a
-> b
-> c
-> d
-> error
-> test_errors.rb
whenver I call Error::TestErrors I got this error, I guess this error is something related to the Zeitwerk
Can someone please help me with this
whenver I call Error::TestErrors I got this error ideally this should work and as it is working on the another branch
The constant
Error::TestErrorswas autoloaded in Rails 6.x. Therefore,libseems to be in the autoload paths andlib/error/test_errors.rbseems to define the expected constant.The exception that you get is
NameError, therefore, this constant is not being autoloaded. If it was, you'd getZeitwerk::NameError. This constant seems to be accessed prematurely, when autoloading is still not ready.We do not have enough evidence, but it is very likely the problem is simply that this constant is being referenced while the application boots, perhaps in an initializer. This has been deprecated since Rails 6.0, and removed in Rails 7.0. This is a conceptual change in Rails, unrelated to Zeitwerk.
If that was right, please, have a look at this section of the upgrading guide to understand how to update the initializer.