You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
NameError: uninitialized constant JSONAPI::ResourceController in Rails 7.1 #1464
Request for support. Note: Please try to avoid submitting issues for support requests. Use Gitter instead.
Checklist before submitting:
I've searched for an existing issue.
I've NOT asked my question on Gitter because Gitter seems to be abandoned by the core team. There a lots of questions posted there that have no responses at all.
I've included a complete bug report template. This step helps us and allows us to see the bug without trying to reproduce the problem from your description. It helps you because you will frequently detect if it's a problem specific to your project.
The feature I'm asking for is compliant with the JSON:API spec.
Description
In trying to update to Rails 7.1 I'm running into random instances of this error when running my test suite.
I also noticed that these errors were only happening locally, and not in CI, and so I tried setting config.eager_load = true in config/environments/test.rb which also made the errors go away.
I poked around this gem a little bit and I think that this block of code isn't exactly working as expected in Rail 7.1.
For anyone else that runs across this it's worth mentioning that another possible app-side fix is manually requiring ResourceController before using it.
For anyone else that runs across this it's worth mentioning that another possible app-side fix is manually requiring ResourceController before using it.
require 'jsonapi/resource_controller'
class Jsonapi::V1::BaseController < JSONAPI::ResourceController
...
end
When did you switch to Zeitwerk? Was it before upgrading to Rails 7.1? Also, was your config.load_defaults set to 5.1 or 5.2?
One app I work with uses Rails 6.1, but the defaults are set to 5.1 (translation: it does not use Zeitwerk). So this same issue surfaces up, and the apparent fix was to quit sessions (Docker Compose...) and reload, and then it stops for a while.
Of course, as your suggestion says, the fix is to require 'jsonapi/resource_controller'.
The thing is, as soon as I switch to use Zetwerk (config.load_defaults = 6.0), the bin/rails zeitwerk:check immediately fails in the base controller where it inherits from < JSONAPI::ResourceController.
Activity
jagthedrummer commentedon Jan 2, 2025
For anyone else that runs across this it's worth mentioning that another possible app-side fix is manually requiring
ResourceControllerbefore using it.zalom commentedon May 26, 2025
When did you switch to Zeitwerk? Was it before upgrading to Rails 7.1? Also, was your
config.load_defaultsset to 5.1 or 5.2?One app I work with uses Rails 6.1, but the defaults are set to 5.1 (translation: it does not use Zeitwerk). So this same issue surfaces up, and the apparent fix was to quit sessions (Docker Compose...) and reload, and then it stops for a while.
Of course, as your suggestion says, the fix is to
require 'jsonapi/resource_controller'.The thing is, as soon as I switch to use Zetwerk (
config.load_defaults = 6.0), thebin/rails zeitwerk:checkimmediately fails in the base controller where it inherits from< JSONAPI::ResourceController.Fix Issue JSONAPI-Resources#1464: Rails 7.1 Zeitwerk autoloading race…
takaokouji commentedon Jan 21, 2026
We've fixed this issue in our fork (speee/jsonapi-resources).
Root cause: The
ActiveSupport.on_load(:action_controller_base)lazy loading mechanism creates a race condition with Zeitwerk in Rails 7.1+.Solution: Remove the conditional lazy loading and always require ResourceController directly. This eliminates the race condition.
Fix: speee#18
If you're experiencing this issue, you can:
require 'jsonapi/resource_controller'before using itHope this helps!
Merge pull request #18 from speee/fix/rails71-zeitwerk-resource-contr…