We've moved discussions to Discord

Heroku deployment: expected file /app/lib/jumpstart/config/routes.rb to define constant Jumpstart::Config::Routes, but didn't (NameError)

Jason Eastwood
I'm receiving the following complaining about the Jumpstart engine's routes file namespacing when deploying my Jumpstart application to Heroku.

The /app/lib/jumpstart/config/routes.rb is defined with the Jumpstart::Engine namespace and Heroku isn't happy.

I haven't seen this problem in my development environment. 

Any ideas what I may have configured incorrectly?

Thank you!

Here's the full stack:

Traceback (most recent call last):
 57: from bin/rails:9:in `<main>'
 56: from /app/vendor/bundle/ruby/2.6.0/gems/activesupport-6.0.0/lib/active_support/dependencies.rb:325:in `require'
 55: from /app/vendor/bundle/ruby/2.6.0/gems/activesupport-6.0.0/lib/active_support/dependencies.rb:291:in `load_dependency'
 54: from /app/vendor/bundle/ruby/2.6.0/gems/activesupport-6.0.0/lib/active_support/dependencies.rb:325:in `block in require'
 53: from /app/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
 52: from /app/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `require_with_bootsnap_lfi'
 51: from /app/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
 50: from /app/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `block in require_with_bootsnap_lfi'
 49: from /app/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require'
 48: from /app/vendor/bundle/ruby/2.6.0/gems/railties-6.0.0/lib/rails/commands.rb:18:in `<main>'
 47: from /app/vendor/bundle/ruby/2.6.0/gems/railties-6.0.0/lib/rails/command.rb:46:in `invoke'
 46: from /app/vendor/bundle/ruby/2.6.0/gems/railties-6.0.0/lib/rails/command/base.rb:65:in `perform'
 45: from /app/vendor/bundle/ruby/2.6.0/gems/thor-0.20.3/lib/thor.rb:387:in `dispatch'
 44: from /app/vendor/bundle/ruby/2.6.0/gems/thor-0.20.3/lib/thor/invocation.rb:126:in `invoke_command'
 43: from /app/vendor/bundle/ruby/2.6.0/gems/thor-0.20.3/lib/thor/command.rb:27:in `run'
 42: from /app/vendor/bundle/ruby/2.6.0/gems/railties-6.0.0/lib/rails/commands/console/console_command.rb:101:in `perform'
 41: from /app/vendor/bundle/ruby/2.6.0/gems/railties-6.0.0/lib/rails/command/actions.rb:15:in `require_application_and_environment!'
 40: from /app/vendor/bundle/ruby/2.6.0/gems/railties-6.0.0/lib/rails/command/actions.rb:28:in `require_environment!'
 39: from /app/vendor/bundle/ruby/2.6.0/gems/railties-6.0.0/lib/rails/application.rb:339:in `require_environment!'
 38: from /app/vendor/bundle/ruby/2.6.0/gems/activesupport-6.0.0/lib/active_support/dependencies.rb:325:in `require'
 37: from /app/vendor/bundle/ruby/2.6.0/gems/activesupport-6.0.0/lib/active_support/dependencies.rb:291:in `load_dependency'
 36: from /app/vendor/bundle/ruby/2.6.0/gems/activesupport-6.0.0/lib/active_support/dependencies.rb:325:in `block in require'
 35: from /app/vendor/bundle/ruby/2.6.0/gems/zeitwerk-2.1.10/lib/zeitwerk/kernel.rb:23:in `require'
 34: from /app/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
 33: from /app/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `require_with_bootsnap_lfi'
 32: from /app/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
 31: from /app/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `block in require_with_bootsnap_lfi'
 30: from /app/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require'
 29: from /app/config/environment.rb:5:in `<main>'
 28: from /app/vendor/bundle/ruby/2.6.0/gems/railties-6.0.0/lib/rails/application.rb:363:in `initialize!'
 27: from /app/vendor/bundle/ruby/2.6.0/gems/railties-6.0.0/lib/rails/initializable.rb:60:in `run_initializers'
 26: from /app/vendor/ruby-2.6.5/lib/ruby/2.6.0/tsort.rb:205:in `tsort_each'
 25: from /app/vendor/ruby-2.6.5/lib/ruby/2.6.0/tsort.rb:226:in `tsort_each'
 24: from /app/vendor/ruby-2.6.5/lib/ruby/2.6.0/tsort.rb:347:in `each_strongly_connected_component'
 23: from /app/vendor/ruby-2.6.5/lib/ruby/2.6.0/tsort.rb:347:in `call'
 22: from /app/vendor/ruby-2.6.5/lib/ruby/2.6.0/tsort.rb:347:in `each'
 21: from /app/vendor/ruby-2.6.5/lib/ruby/2.6.0/tsort.rb:349:in `block in each_strongly_connected_component'
 20: from /app/vendor/ruby-2.6.5/lib/ruby/2.6.0/tsort.rb:431:in `each_strongly_connected_component_from'
 19: from /app/vendor/ruby-2.6.5/lib/ruby/2.6.0/tsort.rb:350:in `block (2 levels) in each_strongly_connected_component'
 18: from /app/vendor/ruby-2.6.5/lib/ruby/2.6.0/tsort.rb:228:in `block in tsort_each'
 17: from /app/vendor/bundle/ruby/2.6.0/gems/railties-6.0.0/lib/rails/initializable.rb:61:in `block in run_initializers'
 16: from /app/vendor/bundle/ruby/2.6.0/gems/railties-6.0.0/lib/rails/initializable.rb:32:in `run'
 15: from /app/vendor/bundle/ruby/2.6.0/gems/railties-6.0.0/lib/rails/initializable.rb:32:in `instance_exec'
 14: from /app/vendor/bundle/ruby/2.6.0/gems/railties-6.0.0/lib/rails/application/finisher.rb:122:in `block in <module:Finisher>'
 13: from /app/vendor/bundle/ruby/2.6.0/gems/zeitwerk-2.1.10/lib/zeitwerk/loader.rb:449:in `eager_load_all'
 12: from /app/vendor/bundle/ruby/2.6.0/gems/zeitwerk-2.1.10/lib/zeitwerk/loader.rb:449:in `each'
 11: from /app/vendor/bundle/ruby/2.6.0/gems/zeitwerk-2.1.10/lib/zeitwerk/loader.rb:338:in `eager_load'
 10: from /app/vendor/bundle/ruby/2.6.0/gems/zeitwerk-2.1.10/lib/zeitwerk/loader.rb:338:in `synchronize'
 9: from /app/vendor/bundle/ruby/2.6.0/gems/zeitwerk-2.1.10/lib/zeitwerk/loader.rb:346:in `block in eager_load'
 8: from /app/vendor/bundle/ruby/2.6.0/gems/zeitwerk-2.1.10/lib/zeitwerk/loader.rb:676:in `ls'
 7: from /app/vendor/bundle/ruby/2.6.0/gems/zeitwerk-2.1.10/lib/zeitwerk/loader.rb:676:in `foreach'
 6: from /app/vendor/bundle/ruby/2.6.0/gems/zeitwerk-2.1.10/lib/zeitwerk/loader.rb:679:in `block in ls'
 5: from /app/vendor/bundle/ruby/2.6.0/gems/zeitwerk-2.1.10/lib/zeitwerk/loader.rb:351:in `block (2 levels) in eager_load'
 4: from /app/vendor/bundle/ruby/2.6.0/gems/zeitwerk-2.1.10/lib/zeitwerk/loader.rb:351:in `const_get'
 3: from /app/vendor/bundle/ruby/2.6.0/gems/zeitwerk-2.1.10/lib/zeitwerk/kernel.rb:16:in `require'
 2: from /app/vendor/bundle/ruby/2.6.0/gems/zeitwerk-2.1.10/lib/zeitwerk/kernel.rb:16:in `tap'
 1: from /app/vendor/bundle/ruby/2.6.0/gems/zeitwerk-2.1.10/lib/zeitwerk/kernel.rb:17:in `block in require'
/app/vendor/bundle/ruby/2.6.0/gems/zeitwerk-2.1.10/lib/zeitwerk/loader/callbacks.rb:17:in `on_file_autoloaded': expected file /app/lib/jumpstart/config/routes.rb to define constant Jumpstart::Config::Routes, but didn't (NameError)
Chris Oliver
Hey  Jason Eastwood ! Interesting issue. I just deployed to Heroku last night and it's working perfect.

Have you modified the autoloader or anything? It sounds like it's trying to load that file as if it were a regular class.
Jason Eastwood
Chris Oliver Actually, yes! 

I added the following to application.rb, essentially copying from a Rails 5 application when I went to register my app/presenters folder.

```
config.eager_load_paths << "#{Rails.root}/lib"
config.eager_load_paths << "#{Rails.root}/app/presenters/**"
config.assets.paths << Rails.root.join("app", "assets", "fonts")
```

Maybe the problem is where i added the lib directory?

I'm not sure if what I added here is even necessary anymore with Rails 6 autoloading? 
Chris Oliver
Yup, the first line where you eager load lib is the problem. The Jumpstart gem is in lib, so you don't want to eager load the whole directory. If you have things you want to load automatically, I'd put them in a folder in lib and eager load that (similar to app/presenters).

Rails 6 also uses Zeitwerk instead of the old autoloader as well. It works a bit differently as well if you want to read up on that.
Jason Eastwood
I'll read up on it! Thank you :)) 
Notifications
You’re not receiving notifications from this thread.