1

Getting ready for Rails 7 by shifting to Zeitwerk autoloader (Rails 6.1.4.4 on Ruby 2.7.5). Turned off the config.autoloader = :classic line in application.rb. App is loading 6.1 defaults.

Dev mode runs fine, but production fails on boot (also fails locally in production mode):

pid=4 tid=2l2g WARN: Zeitwerk::NameError: expected file /app/app/navigation_renderers/public_issue_renderer.rb to define constant PublicIssueRenderer, but didn't
pid=4 tid=2l2g WARN: /app/vendor/bundle/ruby/2.7.0/gems/zeitwerk-2.5.3/lib/zeitwerk/loader/callbacks.rb:25:in `on_file_autoloaded'

(This is on Heroku-20 in a staging environment).

That file does define that as a class, however.:

module SimpleNavigation
  module Renderer
    class PublicIssueRenderer < SimpleNavigation::Renderer::Base
      [functions removed for brevity]
    end
  end
end

I am not sure why the double /app/app exists, as the directory is simply in app along with everything else:

screen shot of file directory from rails app in question

John Athayde
  • 580
  • 2
  • 13

2 Answers2

1

Since app/navigation_renderers belongs to the autoload paths, the file

app/navigation_renderers/public_issue_renderer.rb

should define PublicIssueRenderer at the top-level.

This is the same rule that says that app/models/user.rb has to define exactly User, not SimpleNavigation::Renderer::User.

See?

Also, it is really, really strange that development mode worked in classic with that file. Because that file does not follow classic expectations either, they are the same expectations.

Maybe the application is configuring or doing something funky?

Does bin/rails zeitwerk:check pass? You can run it before deploying. And also you can eager load in CI, which is a good idea (see these docs).

Xavier Noria
  • 1,640
  • 1
  • 8
  • 10
0

The only way I was able to get past this was to put these two lines at the top of the file:

class PublicIssueRenderer
end

and then continue with the module as shown above. Feels wrong, but it passes Zeitwerk and still works.

John Athayde
  • 580
  • 2
  • 13