railsのプロジェクトをEc2にデプロイしたのち、rails console -e production
を行うと次にようなエラーが
[ec2-user@ip-10-0-0-93 room_backend]$ /home/ec2-user/.rbenv/versions/2.6.1/lib/ruby/gems/2.6.0/gems/zeitwerk-2.4.2/lib/zeitwerk/loader/callbacks.rb:18:in `on_file_autoloaded': expected file /var/www/room_backend/app/controllers/v1/auth/customers/confirmations_controller.rb to define constant V1::Auth::Customers::ConfirmationsController, but didn't (Zeitwerk::NameError)
from /home/ec2-user/.rbenv/versions/2.6.1/lib/ruby/gems/2.6.0/gems/zeitwerk-2.4.2/lib/zeitwerk/kernel.rb:27:in `block in require'
from /home/ec2-user/.rbenv/versions/2.6.1/lib/ruby/gems/2.6.0/gems/zeitwerk-2.4.2/lib/zeitwerk/kernel.rb:26:in `tap'
from /home/ec2-user/.rbenv/versions/2.6.1/lib/ruby/gems/2.6.0/gems/zeitwerk-2.4.2/lib/zeitwerk/kernel.rb:26:in `require'
from /home/ec2-user/.rbenv/versions/2.6.1/lib/ruby/gems/2.6.0/gems/zeitwerk-2.4.2/lib/zeitwerk/loader.rb:409:in `const_get'
from /home/ec2-user/.rbenv/versions/2.6.1/lib/ruby/gems/2.6.0/gems/zeitwerk-2.4.2/lib/zeitwerk/loader.rb:409:in `block (2 levels) in eager_load'
from /home/ec2-user/.rbenv/versions/2.6.1/lib/ruby/gems/2.6.0/gems/zeitwerk-2.4.2/lib/zeitwerk/loader.rb:733:in `block in ls'
from /home/ec2-user/.rbenv/versions/2.6.1/lib/ruby/gems/2.6.0/gems/zeitwerk-2.4.2/lib/zeitwerk/loader.rb:725:in `foreach'
from /home/ec2-user/.rbenv/versions/2.6.1/lib/ruby/gems/2.6.0/gems/zeitwerk-2.4.2/lib/zeitwerk/loader.rb:725:in `ls'
from /home/ec2-user/.rbenv/versions/2.6.1/lib/ruby/gems/2.6.0/gems/zeitwerk-2.4.2/lib/zeitwerk/loader.rb:404:in `block in eager_load'
from /home/ec2-user/.rbenv/versions/2.6.1/lib/ruby/gems/2.6.0/gems/zeitwerk-2.4.2/lib/zeitwerk/loader.rb:393:in `synchronize'
from /home/ec2-user/.rbenv/versions/2.6.1/lib/ruby/gems/2.6.0/gems/zeitwerk-2.4.2/lib/zeitwerk/loader.rb:393:in `eager_load'
以下略
エラー名は Zeitwerk::NameError とのこと
ググってみるとスタックオーバーフローにおんなじような記事があったので処置したら治りました
解決法
config/application.rb
class Application < Rails::Application
config.load_defaults 6.0
#下の一行を追加する
config.autoloader = :classic
end