0

When trying to deploy a Rails app to Heroku, the deployment is failing with this error in the release logs:

rake aborted!
KeyError: key not found: :secret_key_base
/app/vendor/bundle/ruby/2.6.0/gems/activesupport-5.2.4.4/lib/active_support/encrypted_configuration.rb:11:in `fetch'
/app/vendor/bundle/ruby/2.6.0/gems/activesupport-5.2.4.4/lib/active_support/encrypted_configuration.rb:11:in `fetch'
/app/config/initializers/devise.rb:313:in `block (2 levels) in <main>'
/app/vendor/bundle/ruby/2.6.0/gems/devise-jwt-0.8.0/lib/devise/jwt.rb:21:in `jwt'
/app/config/initializers/devise.rb:312:in `block in <main>'
/app/vendor/bundle/ruby/2.6.0/gems/devise-4.7.3/lib/devise.rb:307:in `setup'
/app/config/initializers/devise.rb:11:in `<main>'
/app/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:59:in `load'
/app/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:59:in `load'
/app/vendor/bundle/ruby/2.6.0/gems/activesupport-5.2.4.4/lib/active_support/dependencies.rb:285:in `block in load'
/app/vendor/bundle/ruby/2.6.0/gems/activesupport-5.2.4.4/lib/active_support/dependencies.rb:257:in `load_dependency'
/app/vendor/bundle/ruby/2.6.0/gems/activesupport-5.2.4.4/lib/active_support/dependencies.rb:285:in `load'
/app/vendor/bundle/ruby/2.6.0/gems/railties-5.2.4.4/lib/rails/engine.rb:663:in `block in load_config_initializer'
/app/vendor/bundle/ruby/2.6.0/gems/activesupport-5.2.4.4/lib/active_support/notifications.rb:170:in `instrument'
/app/vendor/bundle/ruby/2.6.0/gems/railties-5.2.4.4/lib/rails/engine.rb:662:in `load_config_initializer'
/app/vendor/bundle/ruby/2.6.0/gems/railties-5.2.4.4/lib/rails/engine.rb:620:in `block (2 levels) in <class:Engine>'
/app/vendor/bundle/ruby/2.6.0/gems/railties-5.2.4.4/lib/rails/engine.rb:619:in `each'
/app/vendor/bundle/ruby/2.6.0/gems/railties-5.2.4.4/lib/rails/engine.rb:619:in `block in <class:Engine>'
/app/vendor/bundle/ruby/2.6.0/gems/railties-5.2.4.4/lib/rails/initializable.rb:32:in `instance_exec'
/app/vendor/bundle/ruby/2.6.0/gems/railties-5.2.4.4/lib/rails/initializable.rb:32:in `run'
/app/vendor/bundle/ruby/2.6.0/gems/railties-5.2.4.4/lib/rails/initializable.rb:61:in `block in run_initializers'
/app/vendor/bundle/ruby/2.6.0/gems/railties-5.2.4.4/lib/rails/initializable.rb:50:in `each'
/app/vendor/bundle/ruby/2.6.0/gems/railties-5.2.4.4/lib/rails/initializable.rb:50:in `tsort_each_child'
/app/vendor/bundle/ruby/2.6.0/gems/railties-5.2.4.4/lib/rails/initializable.rb:60:in `run_initializers'
/app/vendor/bundle/ruby/2.6.0/gems/railties-5.2.4.4/lib/rails/application.rb:361:in `initialize!'
/app/config/environment.rb:5:in `<main>'
/app/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
/app/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
/app/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
/app/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
/app/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
/app/vendor/bundle/ruby/2.6.0/gems/activesupport-5.2.4.4/lib/active_support/dependencies.rb:291:in `block in require'
/app/vendor/bundle/ruby/2.6.0/gems/activesupport-5.2.4.4/lib/active_support/dependencies.rb:257:in `load_dependency'
/app/vendor/bundle/ruby/2.6.0/gems/activesupport-5.2.4.4/lib/active_support/dependencies.rb:291:in `require'
/app/vendor/bundle/ruby/2.6.0/gems/railties-5.2.4.4/lib/rails/application.rb:337:in `require_environment!'
/app/vendor/bundle/ruby/2.6.0/gems/railties-5.2.4.4/lib/rails/application.rb:520:in `block in run_tasks_blocks'
Tasks: TOP => db:migrate => db:load_config => environment
(See full trace by running task with --trace)

I've tried a few solutions but getting the same error every time. I've created a secrets.yml file like so:

development:
  secret_key_base: xxxxxxxxx
 
test:
  secret_key_base: xxxxxxxxx
 
production:
  secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>

...but that didn't do anything.

I've tried running heroku config:set secret_key_base=xxxxx and then when I run heroku config again indeed the secret_key_base matches. But I still get the error in the release logs when trying to deploy.

Any help is appreciated; I'm completely lost!

fmp19
  • 1
  • I may have had a similar issue and I got my answer [here](https://stackoverflow.com/questions/63601039/rails-application-credentials-digsecret-key-base-returning-nil-in-heroku-prod). Let me know if it helps you out. – crodev Oct 26 '21 at 13:50
  • Note that the stacktrace is showing you that the missing key is from Devise, not Rails. this https://stackoverflow.com/questions/18080910/devise-secret-key-was-not-set may be helpful – ToTenMilan Oct 26 '21 at 13:55
  • Question needs more investigation – ToTenMilan Oct 26 '21 at 13:57
  • 1
    @crodev this worked perfectly! thanks so much! – fmp19 Oct 27 '21 at 02:40

0 Answers0