0

所以我得到了这个错误: NameError: uninitialized constant which StackOverflow 说意味着它是无意升级的,但这不可能,因为我的版本是最高的,我在 gem 文件中有: gem "aws-sdk-s3",需要:错误的

它可能与初始化文件有关吗?这是构建日志中出错的地方:

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

这是 aws.rb 文件:

AWS::S3::Base.establish_connection!(
    :access_key_id   => ENV['S3_KEY:'],
    :secret_access_key => ENV['S3_SECRET']
   )
   

这是在 Heroku 方面: 在此处输入图像描述

我还不允许嵌入图像,所以只有链接。

好的,我将 aws.rb 文件更改为:

require 'aws-sdk'
AWS::S3::Base.establish_connection!(
    :access_key_id   => ENV['S3_KEY:'],
    :secret_access_key => ENV['S3_SECRET']
   )
   

得到了这个:

 Running: rake assets:precompile
       rake aborted!
       LoadError: cannot load such file -- aws-sdk

我将 AWS gem 更改为: gem 'aws-sdk'

并从构建日志失败中获得此输出:

Running: rake assets:precompile
       rake aborted!
       NameError: uninitialized constant AWS

这是我的 storage.yml 文件的一部分:

# 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

在注释掉 aws.rb 初始化文件并将 storage.yml 更改为以下内容后:

# 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

并添加 Active Storage 构建包,我得到了这个:

###### 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

最近我将 storage.yml 更改为:

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:

警告:检测 rails 配置失败将 HEROKU_DEBUG_RAILS_RUNNER=1 设置为调试

警告:
   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.
4

2 回答 2

0

尝试制作bundle install,它没有帮助,config/initializers/aws.rb与我们分享文件,以更好地了解问题。错误是因为您的应用程序中没有 AWS

于 2020-08-07T20:46:37.447 回答
0

我通过将 Gem 更改为:

 gem 'aws-sdk-v1'

并删除:需要'aws-sdk'。

这对我有用。谢谢

于 2021-02-19T13:35:17.857 回答