'Ruby on Rails 6 Gem::LoadError on aws-sdk-s3 gem

I'm new to Rails and following the Ruby on Rails tutorial by Michael Hartl(Japanese ver ed.6), and trying to Deploy on Heroku with image uploading feature using S3 bucket as storage. After I deploy app on Heroku, I got Gem::Loaderror for the gem "aws-sdk-s3", it says that the gem can't be activated due to the other version of the gem had already been activated.

Error from heroku logs --tail

/app/vendor/bundle/ruby/3.0.0/gems/bundler-2.2.33/lib/bundler/rubygems_integration.rb:332:in `block (2 levels) in replace_gem': can't activate aws-sdk-s3 (~> 1.48), already activated aws-sdk-s3-1.46.0. Make sure all dependencies are added to Gemfile. (Gem::LoadError)

Error form heroku run console

/app/vendor/bundle/ruby/3.0.0/gems/activestorage-6.0.4/lib/active_storage/service/configurator.rb:31:in `rescue in resolve': Cannot load `Rails.config.active_storage.service`: (RuntimeError) Missing service adapter for "S3"

Heroku app crash

at=error code=H10 desc="App crashed" method=GET path="/" host=rails-summer-hibernation.herokuapp.com request_id=6bc58532-f27d-4145-b299-a851ab8295fc fwd="153.240.151.8" dyno= connect= service= status=503 bytes= protocol=https

I looked up for the specified version of gem (which is aws-sdk-s3 (~> 1.48)), but couldn't find anything related from Gemfile and Gemlockfile dependencies. Also tried to find anything related in whole environment nothing found.

Does anyone see what's wrong?

Please tell me if I should provide other files.

Gemfile

git_source(:github) { |repo| "https://github.com/#{repo}.git" }

gem 'rails',                   '6.0.4'
gem 'aws-sdk-s3',              '1.46.0', require: false
gem 'image_processing',           '1.9.3'
gem 'mini_magick',                '4.9.5'
gem 'active_storage_validations', '0.8.2'
gem 'bcrypt',                  '3.1.13'
gem 'faker',                   '2.20.0'
gem 'will_paginate',           '3.3.1'
gem 'bootstrap-will_paginate', '1.0.0'
gem 'bootstrap-sass', '3.4.1'
gem 'puma',       '4.3.6'
gem 'sass-rails', '5.1.0'
gem 'webpacker',  '4.0.7'
gem 'turbolinks', '5.2.0'
gem 'jbuilder',   '2.9.1'
gem 'bootsnap',   '1.10.3', require: false

group :development, :test do
  gem 'sqlite3', '1.4.1'
  gem 'byebug',  '11.0.1', platforms: [:mri, :mingw, :x64_mingw]
end

group :development do
  gem 'web-console',           '4.0.1'
  gem 'listen',                '3.1.5'
  gem 'spring',                '2.1.0'
  gem 'spring-watcher-listen', '2.0.1'
end

group :test do
  gem 'capybara',                 '3.28.0'
  gem 'selenium-webdriver',       '3.142.4'
  gem 'webdrivers',               '4.1.2'
  gem 'rails-controller-testing', '1.0.4'
  gem 'minitest',                 '5.11.3'
  gem 'minitest-reporters',       '1.3.8'
  gem 'guard',                    '2.16.2'
  gem 'guard-minitest',           '2.4.6'
end

group :production do
  gem 'pg', '1.1.4'
end

# Windows ではタイムゾーン情報用の tzinfo-data gem を含める必要があります
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]

Gemlock

  remote: https://rubygems.org/
  specs:
    actioncable (6.0.4)
      actionpack (= 6.0.4)
      nio4r (~> 2.0)
      websocket-driver (>= 0.6.1)
    actionmailbox (6.0.4)
      actionpack (= 6.0.4)
      activejob (= 6.0.4)
      activerecord (= 6.0.4)
      activestorage (= 6.0.4)
      activesupport (= 6.0.4)
      mail (>= 2.7.1)
    actionmailer (6.0.4)
      actionpack (= 6.0.4)
      actionview (= 6.0.4)
      activejob (= 6.0.4)
      mail (~> 2.5, >= 2.5.4)
      rails-dom-testing (~> 2.0)
    actionpack (6.0.4)
      actionview (= 6.0.4)
      activesupport (= 6.0.4)
      rack (~> 2.0, >= 2.0.8)
      rack-test (>= 0.6.3)
      rails-dom-testing (~> 2.0)
      rails-html-sanitizer (~> 1.0, >= 1.2.0)
    actiontext (6.0.4)
      actionpack (= 6.0.4)
      activerecord (= 6.0.4)
      activestorage (= 6.0.4)
      activesupport (= 6.0.4)
      nokogiri (>= 1.8.5)
    actionview (6.0.4)
      activesupport (= 6.0.4)
      builder (~> 3.1)
      erubi (~> 1.4)
      rails-dom-testing (~> 2.0)
      rails-html-sanitizer (~> 1.1, >= 1.2.0)
    active_storage_validations (0.8.2)
      rails (>= 5.2.0)
    activejob (6.0.4)
      activesupport (= 6.0.4)
      globalid (>= 0.3.6)
    activemodel (6.0.4)
      activesupport (= 6.0.4)
    activerecord (6.0.4)
      activemodel (= 6.0.4)
      activesupport (= 6.0.4)
    activestorage (6.0.4)
      actionpack (= 6.0.4)
      activejob (= 6.0.4)
      activerecord (= 6.0.4)
      marcel (~> 1.0.0)
    activesupport (6.0.4)
      concurrent-ruby (~> 1.0, >= 1.0.2)
      i18n (>= 0.7, < 2)
      minitest (~> 5.1)
      tzinfo (~> 1.1)
      zeitwerk (~> 2.2, >= 2.2.2)
    addressable (2.8.0)
      public_suffix (>= 2.0.2, < 5.0)
    ansi (1.5.0)
    autoprefixer-rails (10.4.2.0)
      execjs (~> 2)
    aws-eventstream (1.2.0)
    aws-partitions (1.569.0)
    aws-sdk-core (3.130.0)
      aws-eventstream (~> 1, >= 1.0.2)
      aws-partitions (~> 1, >= 1.525.0)
      aws-sigv4 (~> 1.1)
      jmespath (~> 1.0)
    aws-sdk-kms (1.55.0)
      aws-sdk-core (~> 3, >= 3.127.0)
      aws-sigv4 (~> 1.1)
    aws-sdk-s3 (1.46.0)
      aws-sdk-core (~> 3, >= 3.61.1)
      aws-sdk-kms (~> 1)
      aws-sigv4 (~> 1.1)
    aws-sigv4 (1.4.0)
      aws-eventstream (~> 1, >= 1.0.2)
    bcrypt (3.1.13)
    bindex (0.8.1)
    bootsnap (1.10.3)
      msgpack (~> 1.2)
    bootstrap-sass (3.4.1)
      autoprefixer-rails (>= 5.2.1)
      sassc (>= 2.0.0)
    bootstrap-will_paginate (1.0.0)
      will_paginate
    builder (3.2.4)
    byebug (11.0.1)
    capybara (3.28.0)
      addressable
      mini_mime (>= 0.1.3)
      nokogiri (~> 1.8)
      rack (>= 1.6.0)
      rack-test (>= 0.6.3)
      regexp_parser (~> 1.5)
      xpath (~> 3.2)
    childprocess (2.0.0)
      rake (< 13.0)
    coderay (1.1.3)
    concurrent-ruby (1.1.10)
    crass (1.0.6)
    erubi (1.10.0)
    execjs (2.8.1)
    faker (2.20.0)
      i18n (>= 1.8.11, < 2)
    ffi (1.15.5)
    formatador (1.1.0)
    globalid (1.0.0)
      activesupport (>= 5.0)
    guard (2.16.2)
      formatador (>= 0.2.4)
      listen (>= 2.7, < 4.0)
      lumberjack (>= 1.0.12, < 2.0)
      nenv (~> 0.1)
      notiffany (~> 0.0)
      pry (>= 0.9.12)
      shellany (~> 0.0)
      thor (>= 0.18.1)
    guard-compat (1.2.1)
    guard-minitest (2.4.6)
      guard-compat (~> 1.2)
      minitest (>= 3.0)
    i18n (1.10.0)
      concurrent-ruby (~> 1.0)
    image_processing (1.9.3)
      mini_magick (>= 4.9.5, < 5)
      ruby-vips (>= 2.0.13, < 3)
    jbuilder (2.9.1)
      activesupport (>= 4.2.0)
    jmespath (1.6.1)
    listen (3.1.5)
      rb-fsevent (~> 0.9, >= 0.9.4)
      rb-inotify (~> 0.9, >= 0.9.7)
      ruby_dep (~> 1.2)
    loofah (2.15.0)
      crass (~> 1.0.2)
      nokogiri (>= 1.5.9)
    lumberjack (1.2.8)
    mail (2.7.1)
      mini_mime (>= 0.1.1)
    marcel (1.0.2)
    method_source (1.0.0)
    mini_magick (4.9.5)
    mini_mime (1.1.2)
    minitest (5.11.3)
    minitest-reporters (1.3.8)
      ansi
      builder
      minitest (>= 5.0)
      ruby-progressbar
    msgpack (1.4.5)
    nenv (0.3.0)
    nio4r (2.5.8)
    nokogiri (1.13.3-x86_64-linux)
      racc (~> 1.4)
    notiffany (0.1.3)
      nenv (~> 0.1)
      shellany (~> 0.0)
    pg (1.1.4)
    pry (0.14.1)
      coderay (~> 1.1)
      method_source (~> 1.0)
    public_suffix (4.0.6)
    puma (4.3.6)
      nio4r (~> 2.0)
    racc (1.6.0)
    rack (2.2.3)
    rack-proxy (0.7.2)
      rack
    rack-test (1.1.0)
      rack (>= 1.0, < 3)
    rails (6.0.4)
      actioncable (= 6.0.4)
      actionmailbox (= 6.0.4)
      actionmailer (= 6.0.4)
      actionpack (= 6.0.4)
      actiontext (= 6.0.4)
      actionview (= 6.0.4)
      activejob (= 6.0.4)
      activemodel (= 6.0.4)
      activerecord (= 6.0.4)
      activestorage (= 6.0.4)
      activesupport (= 6.0.4)
      bundler (>= 1.3.0)
      railties (= 6.0.4)
      sprockets-rails (>= 2.0.0)
    rails-controller-testing (1.0.4)
      actionpack (>= 5.0.1.x)
      actionview (>= 5.0.1.x)
      activesupport (>= 5.0.1.x)
    rails-dom-testing (2.0.3)
      activesupport (>= 4.2.0)
      nokogiri (>= 1.6)
    rails-html-sanitizer (1.4.2)
      loofah (~> 2.3)
    railties (6.0.4)
      actionpack (= 6.0.4)
      activesupport (= 6.0.4)
      method_source
      rake (>= 0.8.7)
      thor (>= 0.20.3, < 2.0)
    rake (12.3.3)
    rb-fsevent (0.11.1)
    rb-inotify (0.10.1)
      ffi (~> 1.0)
    regexp_parser (1.8.2)
    ruby-progressbar (1.11.0)
    ruby-vips (2.1.4)
      ffi (~> 1.12)
    ruby_dep (1.5.0)
    rubyzip (1.3.0)
    sass (3.7.4)
      sass-listen (~> 4.0.0)
    sass-listen (4.0.0)
      rb-fsevent (~> 0.9, >= 0.9.4)
      rb-inotify (~> 0.9, >= 0.9.7)
    sass-rails (5.1.0)
      railties (>= 5.2.0)
      sass (~> 3.1)
      sprockets (>= 2.8, < 4.0)
      sprockets-rails (>= 2.0, < 4.0)
      tilt (>= 1.1, < 3)
    sassc (2.4.0)
      ffi (~> 1.9)
    selenium-webdriver (3.142.4)
      childprocess (>= 0.5, < 3.0)
      rubyzip (~> 1.2, >= 1.2.2)
    shellany (0.0.1)
    spring (2.1.0)
    spring-watcher-listen (2.0.1)
      listen (>= 2.7, < 4.0)
      spring (>= 1.2, < 3.0)
    sprockets (3.7.2)
      concurrent-ruby (~> 1.0)
      rack (> 1, < 3)
    sprockets-rails (3.4.2)
      actionpack (>= 5.2)
      activesupport (>= 5.2)
      sprockets (>= 3.0.0)
    sqlite3 (1.4.1)
    thor (1.2.1)
    thread_safe (0.3.6)
    tilt (2.0.10)
    turbolinks (5.2.0)
      turbolinks-source (~> 5.2)
    turbolinks-source (5.2.0)
    tzinfo (1.2.9)
      thread_safe (~> 0.1)
    web-console (4.0.1)
      actionview (>= 6.0.0)
      activemodel (>= 6.0.0)
      bindex (>= 0.4.0)
      railties (>= 6.0.0)
    webdrivers (4.1.2)
      nokogiri (~> 1.6)
      rubyzip (~> 1.0)
      selenium-webdriver (>= 3.0, < 4.0)
    webpacker (4.0.7)
      activesupport (>= 4.2)
      rack-proxy (>= 0.6.1)
      railties (>= 4.2)
    websocket-driver (0.7.5)
      websocket-extensions (>= 0.1.0)
    websocket-extensions (0.1.5)
    will_paginate (3.3.1)
    xpath (3.2.0)
      nokogiri (~> 1.8)
    zeitwerk (2.5.4)

PLATFORMS
  x86_64-linux

DEPENDENCIES
  active_storage_validations (= 0.8.2)
  aws-sdk-s3 (= 1.46.0)
  bcrypt (= 3.1.13)
  bootsnap (= 1.10.3)
  bootstrap-sass (= 3.4.1)
  bootstrap-will_paginate (= 1.0.0)
  byebug (= 11.0.1)
  capybara (= 3.28.0)
  faker (= 2.20.0)
  guard (= 2.16.2)
  guard-minitest (= 2.4.6)
  image_processing (= 1.9.3)
  jbuilder (= 2.9.1)
  listen (= 3.1.5)
  mini_magick (= 4.9.5)
  minitest (= 5.11.3)
  minitest-reporters (= 1.3.8)
  pg (= 1.1.4)
  puma (= 4.3.6)
  rails (= 6.0.4)
  rails-controller-testing (= 1.0.4)
  sass-rails (= 5.1.0)
  selenium-webdriver (= 3.142.4)
  spring (= 2.1.0)
  spring-watcher-listen (= 2.0.1)
  sqlite3 (= 1.4.1)
  turbolinks (= 5.2.0)
  tzinfo-data
  web-console (= 4.0.1)
  webdrivers (= 4.1.2)
  webpacker (= 4.0.7)
  will_paginate (= 3.3.1)

BUNDLED WITH
   2.2.17```


Solution 1:[1]

Use 'aws-sdk' version 3.

# gem 'aws-sdk-s3',              '1.46.0', require: false
gem 'aws-sdk', '~> 3', require: false

This is the same issue that happened in my environment. If you can find the error below in your log, it will be solved in the same way.

/app/vendor/bundle/ruby/3.0.0/gems/bootsnap-1.10.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:27:in `require': cannot load such file -- webrick/httputils (LoadError)

In Chapter 7.5.2 of tutorial, it was changed the web server of heroku from Webrick to puma. However aws-sdk-s3 (version1) has legacy code 'required webrick', this error occurred.

Solution 2:[2]

gem 'aws-sdk-s3', '1.48.0', require: false

Since the error say that 1.48 is already activated, change gem version to 1.48 from 1.46

Really can't find out why the error occur, might be bug.

Received the answer from other platform

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Kenichi
Solution 2 usuraipi