So I got this error: NameError: uninitialized constant which StackOverflow says means that it is unintentionally upgrading, but that cannot be, because my version is the highest, I have in the gem file: gem "aws-sdk-s3", require: false
Could it have to do with the initializer file? This is where in the build log it went wrong:
Preparing app for Rails asset pipeline
Running: rake assets:precompile
rake aborted!
NameError: uninitialized constant AWS
/tmp/build_381cfb05_/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.7/lib/bootsnap/load_path_cache/core_ext/active_support.rb:80:in `block in load_missing_constant'
/tmp/build_381cfb05_/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.7/lib/bootsnap/load_path_cache/core_ext/active_support.rb:9:in `without_bootsnap_cache'
/tmp/build_381cfb05_/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.7/lib/bootsnap/load_path_cache/core_ext/active_support.rb:80:in `rescue in load_missing_constant'
/tmp/build_381cfb05_/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.7/lib/bootsnap/load_path_cache/core_ext/active_support.rb:59:in `load_missing_constant'
/tmp/build_381cfb05_/config/initializers/aws.rb:1:in `<main>'
/tmp/build_381cfb05_/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.7/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:55:in `load'
/tmp/build_381cfb05_/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.7/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:55:in `load'
/tmp/build_381cfb05_/vendor/bundle/ruby/2.6.0/gems/railties-6.0.3.2/lib/rails/engine.rb:666:in `block in load_config_initializer'
/tmp/build_381cfb05_/vendor/bundle/ruby/2.6.0/gems/activesupport-6.0.3.2/lib/active_support/notifications.rb:182:in `instrument'
/tmp/build_381cfb05_/vendor/bundle/ruby/2.6.0/gems/railties-6.0.3.2/lib/rails/engine.rb:665:in `load_config_initializer'
/tmp/build_381cfb05_/vendor/bundle/ruby/2.6.0/gems/railties-6.0.3.2/lib/rails/engine.rb:625:in `block (2 levels) in <class:Engine>'
/tmp/build_381cfb05_/vendor/bundle/ruby/2.6.0/gems/railties-6.0.3.2/lib/rails/engine.rb:624:in `each'
/tmp/build_381cfb05_/vendor/bundle/ruby/2.6.0/gems/railties-6.0.3.2/lib/rails/engine.rb:624:in `block in <class:Engine>'
/tmp/build_381cfb05_/vendor/bundle/ruby/2.6.0/gems/railties-6.0.3.2/lib/rails/initializable.rb:32:in `instance_exec'
/tmp/build_381cfb05_/vendor/bundle/ruby/2.6.0/gems/railties-6.0.3.2/lib/rails/initializable.rb:32:in `run'
/tmp/build_381cfb05_/vendor/bundle/ruby/2.6.0/gems/railties-6.0.3.2/lib/rails/initializable.rb:61:in `block in run_initializers'
/tmp/build_381cfb05_/vendor/bundle/ruby/2.6.0/gems/railties-6.0.3.2/lib/rails/initializable.rb:50:in `each'
/tmp/build_381cfb05_/vendor/bundle/ruby/2.6.0/gems/railties-6.0.3.2/lib/rails/initializable.rb:50:in `tsort_each_child'
/tmp/build_381cfb05_/vendor/bundle/ruby/2.6.0/gems/railties-6.0.3.2/lib/rails/initializable.rb:60:in `run_initializers'
/tmp/build_381cfb05_/vendor/bundle/ruby/2.6.0/gems/railties-6.0.3.2/lib/rails/application.rb:363:in `initialize!'
/tmp/build_381cfb05_/config/environment.rb:5:in `<main>'
/tmp/build_381cfb05_/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.7/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
/tmp/build_381cfb05_/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.7/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
/tmp/build_381cfb05_/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.7/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
/tmp/build_381cfb05_/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.7/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
/tmp/build_381cfb05_/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.7/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
/tmp/build_381cfb05_/vendor/bundle/ruby/2.6.0/gems/zeitwerk-2.4.0/lib/zeitwerk/kernel.rb:34:in `require'
/tmp/build_381cfb05_/vendor/bundle/ruby/2.6.0/gems/railties-6.0.3.2/lib/rails/application.rb:339:in `require_environment!'
/tmp/build_381cfb05_/vendor/bundle/ruby/2.6.0/gems/railties-6.0.3.2/lib/rails/application.rb:523:in `block in run_tasks_blocks'
/tmp/build_381cfb05_/vendor/bundle/ruby/2.6.0/gems/sprockets-rails-3.2.1/lib/sprockets/rails/task.rb:62:in `block (2 levels) in define'
Caused by:
NameError: uninitialized constant AWS
/tmp/build_381cfb05_/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.7/lib/bootsnap/load_path_cache/core_ext/active_support.rb:61:in `block in load_missing_constant'
/tmp/build_381cfb05_/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.7/lib/bootsnap/load_path_cache/core_ext/active_support.rb:17:in `allow_bootsnap_retry'
/tmp/build_381cfb05_/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.7/lib/bootsnap/load_path_cache/core_ext/active_support.rb:60:in `load_missing_constant'
/tmp/build_381cfb05_/config/initializers/aws.rb:1:in `<main>'
/tmp/build_381cfb05_/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.7/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:55:in `load'
/tmp/build_381cfb05_/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.7/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:55:in `load'
/tmp/build_381cfb05_/vendor/bundle/ruby/2.6.0/gems/railties-6.0.3.2/lib/rails/engine.rb:666:in `block in load_config_initializer'
/tmp/build_381cfb05_/vendor/bundle/ruby/2.6.0/gems/activesupport-6.0.3.2/lib/active_support/notifications.rb:182:in `instrument'
/tmp/build_381cfb05_/vendor/bundle/ruby/2.6.0/gems/railties-6.0.3.2/lib/rails/engine.rb:665:in `load_config_initializer'
/tmp/build_381cfb05_/vendor/bundle/ruby/2.6.0/gems/railties-6.0.3.2/lib/rails/engine.rb:625:in `block (2 levels) in <class:Engine>'
/tmp/build_381cfb05_/vendor/bundle/ruby/2.6.0/gems/railties-6.0.3.2/lib/rails/engine.rb:624:in `each'
/tmp/build_381cfb05_/vendor/bundle/ruby/2.6.0/gems/railties-6.0.3.2/lib/rails/engine.rb:624:in `block in <class:Engine>'
/tmp/build_381cfb05_/vendor/bundle/ruby/2.6.0/gems/railties-6.0.3.2/lib/rails/initializable.rb:32:in `instance_exec'
/tmp/build_381cfb05_/vendor/bundle/ruby/2.6.0/gems/railties-6.0.3.2/lib/rails/initializable.rb:32:in `run'
/tmp/build_381cfb05_/vendor/bundle/ruby/2.6.0/gems/railties-6.0.3.2/lib/rails/initializable.rb:61:in `block in run_initializers'
/tmp/build_381cfb05_/vendor/bundle/ruby/2.6.0/gems/railties-6.0.3.2/lib/rails/initializable.rb:50:in `each'
/tmp/build_381cfb05_/vendor/bundle/ruby/2.6.0/gems/railties-6.0.3.2/lib/rails/initializable.rb:50:in `tsort_each_child'
/tmp/build_381cfb05_/vendor/bundle/ruby/2.6.0/gems/railties-6.0.3.2/lib/rails/initializable.rb:60:in `run_initializers'
/tmp/build_381cfb05_/vendor/bundle/ruby/2.6.0/gems/railties-6.0.3.2/lib/rails/application.rb:363:in `initialize!'
/tmp/build_381cfb05_/config/environment.rb:5:in `<main>'
/tmp/build_381cfb05_/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.7/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
/tmp/build_381cfb05_/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.7/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
/tmp/build_381cfb05_/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.7/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
/tmp/build_381cfb05_/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.7/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
/tmp/build_381cfb05_/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.7/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
/tmp/build_381cfb05_/vendor/bundle/ruby/2.6.0/gems/zeitwerk-2.4.0/lib/zeitwerk/kernel.rb:34:in `require'
/tmp/build_381cfb05_/vendor/bundle/ruby/2.6.0/gems/railties-6.0.3.2/lib/rails/application.rb:339:in `require_environment!'
/tmp/build_381cfb05_/vendor/bundle/ruby/2.6.0/gems/railties-6.0.3.2/lib/rails/application.rb:523:in `block in run_tasks_blocks'
/tmp/build_381cfb05_/vendor/bundle/ruby/2.6.0/gems/sprockets-rails-3.2.1/lib/sprockets/rails/task.rb:62:in `block (2 levels) in define'
Tasks: TOP => environment
(See full trace by running task with --trace)
!
! Precompiling assets failed.
!
! Push rejected, failed to compile Ruby app.
! Push failed
This is the aws.rb file:
AWS::S3::Base.establish_connection!(
:access_key_id => ENV['S3_KEY:'],
:secret_access_key => ENV['S3_SECRET']
)
This is on the Heroku side: enter image description here
I'm not allowed to embed images yet so there's the link only.
Okay, I changed the aws.rb file to this:
require 'aws-sdk'
AWS::S3::Base.establish_connection!(
:access_key_id => ENV['S3_KEY:'],
:secret_access_key => ENV['S3_SECRET']
)
And got this:
Running: rake assets:precompile
rake aborted!
LoadError: cannot load such file -- aws-sdk
I changed the AWS gem to: gem 'aws-sdk'
and got this output from the build log failure instead:
Running: rake assets:precompile
rake aborted!
NameError: uninitialized constant AWS
This is part of my storage.yml file:
# Use rails credentials:edit to set the AWS secrets (as aws:access_key_id|secret_access_key)
amazon:
service: S3
#access_key_id: <%= Rails.application.credentials.dig(:aws, :access_key_id) %>
# secret_access_key: <%= Rails.application.credentials.dig(:aws, :secret_access_key) %>
region: us-east-1
bucket: agrifood.bucket
After commenting out the aws.rb intializer file and changing the storage.yml to the below:
# Use rails credentials:edit to set the AWS secrets (as aws:access_key_id|secret_access_key)
amazon:
service: S3
#access_key_id: <%= Rails.application.credentials.dig(:aws, :access_key_id) %>
#access_key_id: <%= Rails.application.credentials.dig(:aws, :access_key_id => ENV['S3_KEY:']) %>
access_key_id: ENV['S3_KEY:'])
secret_access_key: ENV['S3_SECRET'])
#secret_access_key: <%= Rails.application.credentials.dig(:aws, :secret_access_key => ENV['S3_SECRET']) %>
#secret_access_key: <%= Rails.application.credentials.dig(:aws, :secret_access_key) %>
#region: us-east-1
region: eu-west-1
bucket: agrifood.bucket
And adding the Active Storage build pack, I got this:
###### WARNING:
We detected that some binary dependencies required to
use all the preview features of Active Storage are not
present on this system.
For more information please see:
https://devcenter.heroku.com/articles/active-storage-on-heroku
Most recently I changed the storage.yml to this:
amazon:
service: S3
#access_key_id: <%= Rails.application.credentials.dig(:aws, :access_key_id) %>
#access_key_id: <%= Rails.application.credentials.dig(:aws, :access_key_id => ENV['S3_KEY:']) %>
access_key_id: ENV['S3_KEY:'])
secret_access_key: ENV['S3_SECRET'])
#secret_access_key: <%= Rails.application.credentials.dig(:aws, :secret_access_key => ENV['S3_SECRET']) %>
#secret_access_key: <%= Rails.application.credentials.dig(:aws, :secret_access_key) %>
#region: us-east-1
#region: eu-west-1
region: ENV['AWS_BUCKET_REGION'])
bucket: agrifood.bucket
'''
Which still gave me this:
WARNING: Detecting rails configuration failed set HEROKU_DEBUG_RAILS_RUNNER=1 to debug
WARNING: We detected that some binary dependencies required to
use all the preview features of Active Storage are not
present on this system.
I then changed it to this:
Aws.config.update({ region: 'eu-west-1', credentials: Aws::Credentials.new(ENV['S3_KEY:'], ENV['S3_SECRET']), })
S3_BUCKET = Aws::S3::Resource.new.bucket(ENV['S3_BUCKET'])
As per the advice to changed AWS to Aws I did what is just above, however, that didn't fix it.
require
d the aws sdk before any usages of AWS (that can be done in an initializer)? Have you tried to removerequire: false
from the gemfile? – Mahmoud SayedAws
constant instead – Ninh Lerequire: false
from Gemfile and re-runbundle install
. – Mahmoud Sayed