Hi,
It’s been a few hours and I am still fighting with a “A copy of XXX has been removed from the module tree but is still active!”.
My goal with this post is to discuss shouldn’t there be more information about this particular error on the rails guides. Sorry if there already is, but I could not find it.
The error is commonly occurring (a few searches): Search results for 'has been removed from the module tree but is still active' - Ruby on Rails Discussions! Human verification - Stack Overflow
There are answers from 2009, there are answers with Dependencies before it was in ActiveSupport, there are some answers that are plain wrong, there are dozens of blogs posts, but I could not find an explanation and example on the rails guides.
People are suggesting things like (to list a few)
config.paths.add
config.autoload_paths
config.eager_load_paths
Zeitwerk::Loader.eager_load_all
config.eager_load_namespaces
require_dependency
Rails.application.eager_load!
Rails.configuration.eager_load_namespaces.each(&:eager_load!)
Dependencies.load_once_paths
unloadable
I’ve been through:
https://apidock.com/rails/ActiveSupport/Dependencies/Loadable/unloadable
and through many more, but I cant find an example that would lead to this error and explanation on why it occurs and how to fix it.
I personally kind of understand the error and why it is happening, yet I still can’t find a way to resolve it in my case. My specific case even involves spring and the class in question comes from an Engine and it only occurs after a spec has failed. So it makes things more difficult.
My recommendation is that we should build an ‘example’ of when and how such an error could occur in an real life scenario. Looking at activesupport-6.0.3.1/lib/active_support/dependencies.rb:529 there are more cases where similar errors could occur.
I would love to volunteer, but I do not think I understand the error well enough (I still can not resolve it in my case).
I would also not argue that there should be a more understandable explanation for every ‘error’ there is and how to approach it, but following the May of WTF posts last month, there could be an added value if more examples and explanations are added about this particular error.