heroku 未初始化的常量ActiveJob::Serializers

0lvr5msh  于 2023-05-07  发布在  其他
关注(0)|答案(1)|浏览(127)

我正在尝试更新一个旧的Rails应用程序,以便在heroku-20堆栈上运行。我正在运行Rails 5.1.1和shopify-money 1.1.2。它在本地工作,一切似乎都正确地部署到heroku,但当我尝试启动应用程序时,我得到以下错误:
gems/shopify-money-1.1.2/lib/money/rails/job_argument_serializer.rb:5:in 'module:Rails': uninitialized constant ActiveJob::Serializers (NameError)
当我尝试重新加载数据库时,我得到一个更完整的错误消息:

heroku run bundle exec rake db:reload -a kiddocloud-staging
Running bundle exec rake db:reload on ⬢ kiddocloud-staging... up, run.3483 (Eco)
W, [2023-05-04T22:55:19.644207 #2]  WARN -- sentry: ** [Raven] You are running on Heroku but haven't enabled Dyno Metadata. For Sentry's release detection to work correctly, please run `heroku labs:enable runtime-dyno-metadata`
D, [2023-05-04T22:55:19.708017 #2] DEBUG -- : uninitialized constant ActiveJob::Serializers excluded from capture: DSN not set
rake aborted!
NameError: uninitialized constant ActiveJob::Serializers
/app/vendor/bundle/ruby/2.6.0/gems/shopify-money-1.1.2/lib/money/rails/job_argument_serializer.rb:5:in `<module:Rails>'
/app/vendor/bundle/ruby/2.6.0/gems/shopify-money-1.1.2/lib/money/rails/job_argument_serializer.rb:4:in `<class:Money>'
/app/vendor/bundle/ruby/2.6.0/gems/shopify-money-1.1.2/lib/money/rails/job_argument_serializer.rb:3:in `<top (required)>'
/app/vendor/bundle/ruby/2.6.0/gems/shopify-money-1.1.2/lib/money/railtie.rb:7:in `require_relative'
/app/vendor/bundle/ruby/2.6.0/gems/shopify-money-1.1.2/lib/money/railtie.rb:7:in `block (2 levels) in <class:Railtie>'
/app/vendor/bundle/ruby/2.6.0/gems/activesupport-5.1.1/lib/active_support/lazy_load_hooks.rb:45:in `instance_eval'
/app/vendor/bundle/ruby/2.6.0/gems/activesupport-5.1.1/lib/active_support/lazy_load_hooks.rb:45:in `execute_hook'
/app/vendor/bundle/ruby/2.6.0/gems/activesupport-5.1.1/lib/active_support/lazy_load_hooks.rb:35:in `block in on_load'
/app/vendor/bundle/ruby/2.6.0/gems/activesupport-5.1.1/lib/active_support/lazy_load_hooks.rb:34:in `each'
/app/vendor/bundle/ruby/2.6.0/gems/activesupport-5.1.1/lib/active_support/lazy_load_hooks.rb:34:in `on_load'
/app/vendor/bundle/ruby/2.6.0/gems/shopify-money-1.1.2/lib/money/railtie.rb:6:in `block in <class:Railtie>'
/app/vendor/bundle/ruby/2.6.0/gems/railties-5.1.1/lib/rails/initializable.rb:30:in `instance_exec'
/app/vendor/bundle/ruby/2.6.0/gems/railties-5.1.1/lib/rails/initializable.rb:30:in `run'
/app/vendor/bundle/ruby/2.6.0/gems/railties-5.1.1/lib/rails/initializable.rb:59:in `block in run_initializers'
/app/vendor/bundle/ruby/2.6.0/gems/railties-5.1.1/lib/rails/initializable.rb:58:in `run_initializers'
/app/vendor/bundle/ruby/2.6.0/gems/railties-5.1.1/lib/rails/application.rb:353:in `initialize!'
/app/config/environment.rb:5:in `<top (required)>'
/app/vendor/bundle/ruby/2.6.0/gems/railties-5.1.1/lib/rails/application.rb:329:in `require_environment!'
/app/vendor/bundle/ruby/2.6.0/gems/railties-5.1.1/lib/rails/application.rb:445:in `block in run_tasks_blocks'
/app/vendor/bundle/ruby/2.6.0/gems/rake-13.0.6/exe/rake:27:in `<top (required)>'
/app/vendor/bundle/ruby/2.6.0/gems/bundler-1.17.3/lib/bundler/cli/exec.rb:74:in `load'
/app/vendor/bundle/ruby/2.6.0/gems/bundler-1.17.3/lib/bundler/cli/exec.rb:74:in `kernel_load'
/app/vendor/bundle/ruby/2.6.0/gems/bundler-1.17.3/lib/bundler/cli/exec.rb:28:in `run'
/app/vendor/bundle/ruby/2.6.0/gems/bundler-1.17.3/lib/bundler/cli.rb:463:in `exec'
/app/vendor/bundle/ruby/2.6.0/gems/bundler-1.17.3/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
/app/vendor/bundle/ruby/2.6.0/gems/bundler-1.17.3/lib/bundler/vendor/thor/lib/thor/invocation.rb:126:in `invoke_command'
/app/vendor/bundle/ruby/2.6.0/gems/bundler-1.17.3/lib/bundler/vendor/thor/lib/thor.rb:387:in `dispatch'
/app/vendor/bundle/ruby/2.6.0/gems/bundler-1.17.3/lib/bundler/cli.rb:27:in `dispatch'
/app/vendor/bundle/ruby/2.6.0/gems/bundler-1.17.3/lib/bundler/vendor/thor/lib/thor/base.rb:466:in `start'
/app/vendor/bundle/ruby/2.6.0/gems/bundler-1.17.3/lib/bundler/cli.rb:18:in `start'
/app/vendor/bundle/ruby/2.6.0/gems/bundler-1.17.3/exe/bundle:30:in `block in <top (required)>'
/app/vendor/bundle/ruby/2.6.0/gems/bundler-1.17.3/lib/bundler/friendly_errors.rb:124:in `with_friendly_errors'
/app/vendor/bundle/ruby/2.6.0/gems/bundler-1.17.3/exe/bundle:22:in `<top (required)>'
/app/bin/bundle:3:in `load'
/app/bin/bundle:3:in `<main>'
Tasks: TOP => db:reload => environment
(See full trace by running task with --trace)

这是一回事。它似乎找不到ActiveJob::Serializers,即使Rails 5.0.0及更高版本应该有...救命啊!

lndjwyie

lndjwyie1#

这是一个早期的摇摆。
是的,Rails有ActiveJob::Serializers,我猜当shopify-money被加载时,它还没有被初始化。
我猜它在本地工作,因为production.rb有一些development.rb没有的东西,那就是试图在**ActiveJob之前加载这个gem。
为了确认,您可以尝试在本地执行RAILS_ENV=production rails console。它应该以同样的方式失败。
至于修复,您的选择是推迟加载gem的JobArgumentSerializer,直到您确定所有Rails都已加载,或者相反,确保在任何shopify-money代码之前加载require "active_job/serializers"
application.rb中,我希望看到这样的内容:

require "rails" #<- all of Rails, including ActiveJob
...
Bundler.require(*Rails.groups) #<- requires the gems from your Gemfile

这确保了所有的gem都在Rails之后加载。
我猜在初始化器或production.rb中有一些东西试图在加载application.rb文件之前使用gem。

相关问题