我正在尝试更新旧的 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 及更高版本应该有......帮助!
对此的早期摇摆。
是的,Rails 有
ActiveJob::Serializers
,我猜它只是 yet 在 shopify-money
加载时初始化。
我猜它在本地工作,因为
production.rb
有一些development.rb
没有的东西试图加载这个宝石beforeActiveJob
.
要确认,您可以尝试在本地执行
RAILS_ENV=production rails console
。它应该以同样的方式失败。
JobArgumentSerializer
,直到您确定所有 Rails 都已加载或执行相反的操作,并确保 require "active_job/serializers"
在任何 shopify-money
代码之前。
在
application.rb
,我希望看到这样的东西:
require "rails" #<- all of Rails, including ActiveJob
...
Bundler.require(*Rails.groups) #<- requires the gems from your Gemfile
这确保所有的宝石都在 Rails 之后加载。
我猜你在初始化器或
production.rb
中有一些东西在加载 application.rb
文件之前尝试使用 gem.