1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Rails (V1::Auth::Customers::ConfirmationsController, but didn't (Zeitwerk::NameError))

Posted at

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
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?