rails: can't run with production env

Steps to reproduce

step0 : rails new lark_pipeline --skip-action-mailer --skip-action-mailbox
step1: run the app with production env in RubyMine

Expected behavior

run the app

Actual behavior

crashed and outpu:

/bin/zsh -c "bash -c 'env RBENV_VERSION=2.6.4 /usr/local/Cellar/rbenv/1.1.2/libexec/rbenv exec ruby /Users/dongzhao/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/ruby-debug-ide-0.8.0.beta8/bin/rdebug-ide --key-value --step-over-in-blocks --disable-int-handler --evaluation-timeout 10 --evaluation-control --time-limit 100 --memory-limit 0 --rubymine-protocol-extensions --port 49676 --host 0.0.0.0 --dispatcher-port 49677 -- /Volumes/PSSD/Bytedance/tools/pipeline/lark_pipeline/bin/rails server -b 0.0.0.0 -p 3000 -e production'"
Fast Debugger (ruby-debug-ide 0.8.0.beta8, debase 0.3.0.beta8, file filtering is supported, block breakpoints supported, smart steps supported, obtaining return values supported) listens on 0.0.0.0:49676
=> Booting Puma
=> Rails 6.0.2.1 application starting in production 
=> Run `rails server --help` for more startup options
Exiting
Uncaught exception: uninitialized constant #<Class:0x00007fa4c6a93ba8>::Analyzable
Did you mean?  ActiveStorage::Analyzer
	/Users/dongzhao/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/activestorage-6.0.2.1/app/models/active_storage/blob.rb:26:in `<class:Blob>'
	/Users/dongzhao/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/activestorage-6.0.2.1/app/models/active_storage/blob.rb:19:in `<main>'
	/Users/dongzhao/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
	/Users/dongzhao/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
	/Users/dongzhao/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
	/Users/dongzhao/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
	/Users/dongzhao/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
	/Users/dongzhao/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/zeitwerk-2.3.0/lib/zeitwerk/kernel.rb:16:in `require'
	/Users/dongzhao/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/zeitwerk-2.3.0/lib/zeitwerk/loader.rb:381:in `const_get'
	/Users/dongzhao/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/zeitwerk-2.3.0/lib/zeitwerk/loader.rb:381:in `block (2 levels) in eager_load'
	/Users/dongzhao/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/zeitwerk-2.3.0/lib/zeitwerk/loader.rb:723:in `block in ls'
	/Users/dongzhao/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/zeitwerk-2.3.0/lib/zeitwerk/loader.rb:720:in `foreach'
	/Users/dongzhao/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/zeitwerk-2.3.0/lib/zeitwerk/loader.rb:720:in `ls'
	/Users/dongzhao/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/zeitwerk-2.3.0/lib/zeitwerk/loader.rb:376:in `block in eager_load'
	/Users/dongzhao/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/zeitwerk-2.3.0/lib/zeitwerk/loader.rb:368:in `synchronize'
	/Users/dongzhao/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/zeitwerk-2.3.0/lib/zeitwerk/loader.rb:368:in `eager_load'
	/Users/dongzhao/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/zeitwerk-2.3.0/lib/zeitwerk/loader.rb:483:in `each'
	/Users/dongzhao/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/zeitwerk-2.3.0/lib/zeitwerk/loader.rb:483:in `eager_load_all'
	/Users/dongzhao/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/railties-6.0.2.1/lib/rails/application/finisher.rb:122:in `block in <module:Finisher>'
	/Users/dongzhao/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/railties-6.0.2.1/lib/rails/initializable.rb:32:in `instance_exec'
	/Users/dongzhao/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/railties-6.0.2.1/lib/rails/initializable.rb:32:in `run'
	/Users/dongzhao/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/railties-6.0.2.1/lib/rails/initializable.rb:61:in `block in run_initializers'
	/Users/dongzhao/.rbenv/versions/2.6.4/lib/ruby/2.6.0/tsort.rb:228:in `block in tsort_each'
	/Users/dongzhao/.rbenv/versions/2.6.4/lib/ruby/2.6.0/tsort.rb:350:in `block (2 levels) in each_strongly_connected_component'
	/Users/dongzhao/.rbenv/versions/2.6.4/lib/ruby/2.6.0/tsort.rb:431:in `each_strongly_connected_component_from'
	/Users/dongzhao/.rbenv/versions/2.6.4/lib/ruby/2.6.0/tsort.rb:349:in `block in each_strongly_connected_component'
	/Users/dongzhao/.rbenv/versions/2.6.4/lib/ruby/2.6.0/tsort.rb:347:in `each'
	/Users/dongzhao/.rbenv/versions/2.6.4/lib/ruby/2.6.0/tsort.rb:347:in `call'
	/Users/dongzhao/.rbenv/versions/2.6.4/lib/ruby/2.6.0/tsort.rb:347:in `each_strongly_connected_component'
	/Users/dongzhao/.rbenv/versions/2.6.4/lib/ruby/2.6.0/tsort.rb:226:in `tsort_each'
	/Users/dongzhao/.rbenv/versions/2.6.4/lib/ruby/2.6.0/tsort.rb:205:in `tsort_each'
	/Users/dongzhao/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/railties-6.0.2.1/lib/rails/initializable.rb:60:in `run_initializers'
	/Users/dongzhao/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/railties-6.0.2.1/lib/rails/application.rb:363:in `initialize!'
	/Volumes/PSSD/Bytedance/tools/pipeline/lark_pipeline/config/environment.rb:5:in `<main>'
	/Users/dongzhao/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
	/Users/dongzhao/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
	/Users/dongzhao/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
	/Users/dongzhao/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
	/Users/dongzhao/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
	/Users/dongzhao/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/zeitwerk-2.3.0/lib/zeitwerk/kernel.rb:23:in `require'
	/Users/dongzhao/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/activesupport-6.0.2.1/lib/active_support/dependencies.rb:325:in `block in require'
	/Users/dongzhao/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/activesupport-6.0.2.1/lib/active_support/dependencies.rb:291:in `load_dependency'
	/Users/dongzhao/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/activesupport-6.0.2.1/lib/active_support/dependencies.rb:325:in `require'
	/Users/dongzhao/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:49:in `require_relative'
	config.ru:3:in `block in <main>'
	/Users/dongzhao/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/rack-2.2.2/lib/rack/builder.rb:116:in `eval'
	/Users/dongzhao/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/rack-2.2.2/lib/rack/builder.rb:116:in `new_from_string'
	/Users/dongzhao/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/rack-2.2.2/lib/rack/builder.rb:105:in `load_file'
	/Users/dongzhao/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/rack-2.2.2/lib/rack/builder.rb:66:in `parse_file'
	/Users/dongzhao/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/rack-2.2.2/lib/rack/server.rb:349:in `build_app_and_options_from_config'
	/Users/dongzhao/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/rack-2.2.2/lib/rack/server.rb:249:in `app'
	/Users/dongzhao/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/rack-2.2.2/lib/rack/server.rb:422:in `wrapped_app'
	/Users/dongzhao/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/rack-2.2.2/lib/rack/server.rb:312:in `block in start'
	/Users/dongzhao/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/rack-2.2.2/lib/rack/server.rb:379:in `handle_profiling'
	/Users/dongzhao/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/rack-2.2.2/lib/rack/server.rb:311:in `start'
	/Users/dongzhao/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/railties-6.0.2.1/lib/rails/commands/server/server_command.rb:39:in `start'
	/Users/dongzhao/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/railties-6.0.2.1/lib/rails/commands/server/server_command.rb:147:in `block in perform'
	/Users/dongzhao/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/railties-6.0.2.1/lib/rails/commands/server/server_command.rb:138:in `tap'
	/Users/dongzhao/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/railties-6.0.2.1/lib/rails/commands/server/server_command.rb:138:in `perform'
	/Users/dongzhao/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/thor-1.0.1/lib/thor/command.rb:27:in `run'
	/Users/dongzhao/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/thor-1.0.1/lib/thor/invocation.rb:127:in `invoke_command'
	/Users/dongzhao/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/thor-1.0.1/lib/thor.rb:392:in `dispatch'
	/Users/dongzhao/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/railties-6.0.2.1/lib/rails/command/base.rb:69:in `perform'
	/Users/dongzhao/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/railties-6.0.2.1/lib/rails/command.rb:46:in `invoke'
	/Users/dongzhao/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/railties-6.0.2.1/lib/rails/commands.rb:18:in `<main>'
	/Users/dongzhao/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
	/Users/dongzhao/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
	/Users/dongzhao/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
	/Users/dongzhao/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
	/Users/dongzhao/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
	/Users/dongzhao/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/activesupport-6.0.2.1/lib/active_support/dependencies.rb:325:in `block in require'
	/Users/dongzhao/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/activesupport-6.0.2.1/lib/active_support/dependencies.rb:291:in `load_dependency'
	/Users/dongzhao/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/activesupport-6.0.2.1/lib/active_support/dependencies.rb:325:in `require'
	/Volumes/PSSD/Bytedance/tools/pipeline/lark_pipeline/bin/rails:9:in `<top (required)>'
	/Users/dongzhao/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/spring-2.1.0/lib/spring/client/rails.rb:28:in `load'
	/Users/dongzhao/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/spring-2.1.0/lib/spring/client/rails.rb:28:in `call'
	/Users/dongzhao/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/spring-2.1.0/lib/spring/client/command.rb:7:in `call'
	/Users/dongzhao/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/spring-2.1.0/lib/spring/client.rb:30:in `run'
	/Users/dongzhao/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/spring-2.1.0/bin/spring:49:in `<top (required)>'
	/Users/dongzhao/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/spring-2.1.0/lib/spring/binstub.rb:11:in `load'
	/Users/dongzhao/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/spring-2.1.0/lib/spring/binstub.rb:11:in `<top (required)>'
	/Users/dongzhao/.rbenv/versions/2.6.4/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
	/Users/dongzhao/.rbenv/versions/2.6.4/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
	/Volumes/PSSD/Bytedance/tools/pipeline/lark_pipeline/bin/spring:15:in `<top (required)>'
	/Volumes/PSSD/Bytedance/tools/pipeline/lark_pipeline/bin/rails:3:in `load'
	/Volumes/PSSD/Bytedance/tools/pipeline/lark_pipeline/bin/rails:3:in `<top (required)>'

Process finished with exit code 0

System configuration

Rails version: 6.0.2.1 Ruby version: 2.6.4

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 3
  • Comments: 27 (5 by maintainers)

Most upvoted comments

Hi, please can someone reopen this issue? The original author may not have provided the requested information, but I have, and it’s clear that there is some sort of issue here, as it’s been reported by multiple individuals across different platforms.

Same issue here

I encountered a similar error intermittently when using binding.pry in a spec while using guard.

Error I get: NameError: uninitialized constant #<Class:0x00000001225bd010>::Analyzable from /Users/weston/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/activestorage-6.1.4.1/app/models/active_storage/blob.rb:33:in '<class:Blob>'

I work around it with this in an initializer:

Rails.application.reloader.to_prepare do
  ActiveStorage::Blob
end

I had the same issue in development mode. I solved it by opting out from Zeitwek Mode and using the classic mode instead. Autoloading and Reloading Constants (Zeitwerk Mode)

Rails version             6.0.3.3
Ruby version              ruby 2.7.0p0 (2019-12-25 revision 647ee6f091) [x86_64-linux]
RubyGems version          3.1.4
Rack version              2.2.3

/config/environments/development.rb

config.autoloader = :classic

Same problem on Rails 6.1.1, Ruby 3, also

config.autoloader = :classic

solved problem

Try to Include

config/application.rb config.autoloader = :classic

Hey @rafaelfranca as @mashedkeyboard mentioned is there anyway this could be reopened? This is just totally broken for me with a pretty generic setup.

For what it’s worth I’m on ruby '2.7.1' rails 6.0.3.2'

I am also facing the same issue on Rails: 6.0.3.2 Ruby 2.6.6 I do see a related commit in master https://github.com/rails/rails/commit/c7c3abe03b8e2848990bdb83831e4e30cbd97d02#diff-123aa7e5579a68c3dc535779855c51e1 related to workaround suggested by @gkpacker . However, the exact diff does not work for me, I need to do both require_dependency as well as include ActiveStorage::Blob::Analyzable . I tried reverting back to the classic autoloading mode, but got the same error.

Same issue: Ruby: ruby 2.7.1p83 (2020-03-31 revision a0c7c23c9c) [x86_64-darwin18]

[2] pry> model = create(:store_import)
=> #<StoreImport:0x00007ff17be3dba8 id: 2, desc: "MyString", kind: nil, created_at: Fri, 19 Jun 2020 02:00:52 UTC +00:00, updated_at: Fri, 19 Jun 2020 02:00:52 UTC +00:00>
[3] pry> model.import_file.attach(io: File.open(file_name),
[3] pry> *   filename: 'users.xlsx',
[3] pry>* content_type: 'application/xlsx')
NameError: uninitialized constant #<Class:0x00007ff17bce6778>::Analyzable
from /Users/aleksandrbobrov/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/activestorage-6.0.3.2/app/models/active_storage/blob.rb:26:in `<class:Blob>'

Yes remove conditions make it work:

#  unless Rails.autoloaders.zeitwerk_enabled?
    require_dependency "active_storage/blob/analyzable"
    require_dependency "active_storage/blob/identifiable"
    require_dependency "active_storage/blob/representable"
#  end

  include Analyzable
  include Identifiable
  include Representable

I had the same problem in test mode, using spring. I had to turn on eager loading to make it works.

config.eager_load = true

Same problem using Active Storage on Rails 6.1. config.autoloader = :classic solves the problem