简体   繁体   中英

Puma: Unable to load application: NameError: uninitialized constant

When I am trying to deploy an rails application to Heroku, I am getting this error:

Puma starting in single mode...
2017-02-27T15:08:03.908788+00:00 app[web.1]: * Version 3.7.0 (ruby 2.3.1-p112), codename: Snowy Sagebrush
2017-02-27T15:08:03.908789+00:00 app[web.1]: * Min threads: 5, max threads: 5
2017-02-27T15:08:03.908790+00:00 app[web.1]: * Environment: production
2017-02-27T15:08:05.942041+00:00 app[web.1]: ! Unable to load application: NameError: uninitialized constant Api::V1::AController
2017-02-27T15:08:05.942133+00:00 app[web.1]: bundler: failed to load command: puma (/app/vendor/bundle/ruby/2.3.0/bin/puma)
2017-02-27T15:08:05.942266+00:00 app[web.1]: NameError: uninitialized constant Api::V1::AController

Here is the link to the full log

If I try to run the following code on my dev environment, everything works just fine:

bundle exec puma -C config/puma.rb

I ran rails on my local machine using the -e production flag and it runs ok, no error appears. This happens only when I deploy to Heroku.

puma.rb

workers Integer(ENV['WEB_CONCURRENCY'] || 2)
threads_count = Integer(ENV['RAILS_MAX_THREADS'] || 5)
threads threads_count, threads_count

preload_app!

rackup      DefaultRackup
port        ENV['PORT']     || 3000
environment ENV['RACK_ENV'] || 'development'

on_worker_boot do
    ActiveRecord::Base.establish_connection
end

What I've tried:

  1. Created a new instance on Heroku just to be sure there was not a problem with the current instance
  2. Tested multiple versions of Puma
  3. Checked development.rb and production.rb to see what was different

What I am doing right now:

  1. Going through each commit to find what changed in the app and try to find the cause of the app

I believe I am overcomplicating the problem... Any thoughts on this?

Try to reproduce this problem on your local machine by setting all environmental variables to the same values as on Heroku. Or at least set all variables used by puma:

RAILS_ENV=production RACK_ENV=production WEB_CONCURRENCY=1 RAILS_MAX_THREADS=5 bundle exec puma -C config/puma.rb

Also I've noticed that you are using threads. Is it on purpose? I mean ruby ecosystem is not famous for thread safety. Try changing RAILS_MAX_THREADS to 1 and bump WEB_CONCURRENCY to higher number.

For me, the application was not using ActiveRecord, but there were still references to it. Because require "active_record/railtie" was commented out, it broke on production.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM