LoginSignup
5
1

More than 1 year has passed since last update.

【Railsチュートリアル】1章のHerokuデプロイでArgumentError

Last updated at Posted at 2022-03-15

要約

HerokuでサポートされているRubyのバージョンと手元のバージョンを揃えたら解消した。

概要

Railsチュートリアル第4版の「1.5.2 Herokuにデプロイする (1)」でエラーが発生し、デプロイできなかった。

環境

チュートリアル通りの手順で環境構築。

  • OS:Ubuntu18.04 (AWSのCloud9を利用)
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=18.04
DISTRIB_CODENAME=bionic
DISTRIB_DESCRIPTION="Ubuntu 18.04.6 LTS"
  • Rails:5.1.6
  • Ruby:2.6.3
  • Gemfile:以下の通り
Gemfile
source 'https://rubygems.org'

gem 'rails',        '5.1.6'
gem 'puma',         '3.9.1'
gem 'sass-rails',   '5.0.6'
gem 'uglifier',     '3.2.0'
gem 'coffee-rails', '4.2.2'
gem 'jquery-rails', '4.3.1'
gem 'turbolinks',   '5.0.1'
gem 'jbuilder',     '2.6.4'

group :development, :test do
  gem 'sqlite3',      '1.3.13'
  gem 'byebug', '9.0.6', platform: :mri
end

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

経緯

Railsチュートリアル第4版に着手しており、「1.5.1 Herokuのセットアップ」まで完了。

RailsアプリケーションをHerokuにデプロイ。

$ git push heroku master

するとエラーが発生しデプロイに失敗。アプリのプリコンパイルに失敗した模様。
HerokuのダッシュボードのActivityにあるログは以下の通り。

-----> Building on the Heroku-20 stack
-----> Determining which buildpack to use for this app
 !     Warning: Multiple default buildpacks reported the ability to handle this app. The first buildpack in the list below will be used.
			Detected buildpacks: Ruby,Node.js
			See https://devcenter.heroku.com/articles/buildpacks#buildpack-detect-order
-----> Ruby app detected
-----> Installing bundler 1.17.3
-----> Removing BUNDLED WITH version in the Gemfile.lock
-----> Compiling Ruby/Rails
-----> Using Ruby version: ruby-3.0.3
-----> Installing dependencies using bundler 1.17.3

===省略===

-----> Installing node-v16.13.1-linux-x64
-----> Detecting rake tasks
-----> Preparing app for Rails asset pipeline
       Running: rake assets:precompile
       rake aborted!
       ArgumentError: wrong number of arguments (given 3, expected 2)
       /tmp/build_66b113d2/vendor/bundle/ruby/3.0.0/gems/actionpack-5.1.6/lib/action_dispatch/middleware/static.rb:109:in `initialize'
       /tmp/build_66b113d2/vendor/bundle/ruby/3.0.0/gems/actionpack-5.1.6/lib/action_dispatch/middleware/stack.rb:35:in `new'
       /tmp/build_66b113d2/vendor/bundle/ruby/3.0.0/gems/actionpack-5.1.6/lib/action_dispatch/middleware/stack.rb:35:in `build'
       /tmp/build_66b113d2/vendor/bundle/ruby/3.0.0/gems/actionpack-5.1.6/lib/action_dispatch/middleware/stack.rb:99:in `block in build'
       /tmp/build_66b113d2/vendor/bundle/ruby/3.0.0/gems/actionpack-5.1.6/lib/action_dispatch/middleware/stack.rb:99:in `each'
       /tmp/build_66b113d2/vendor/bundle/ruby/3.0.0/gems/actionpack-5.1.6/lib/action_dispatch/middleware/stack.rb:99:in `inject'
       /tmp/build_66b113d2/vendor/bundle/ruby/3.0.0/gems/actionpack-5.1.6/lib/action_dispatch/middleware/stack.rb:99:in `build'
       /tmp/build_66b113d2/vendor/bundle/ruby/3.0.0/gems/railties-5.1.6/lib/rails/engine.rb:508:in `block in app'
       /tmp/build_66b113d2/vendor/bundle/ruby/3.0.0/gems/railties-5.1.6/lib/rails/engine.rb:504:in `synchronize'
       /tmp/build_66b113d2/vendor/bundle/ruby/3.0.0/gems/railties-5.1.6/lib/rails/engine.rb:504:in `app'
       /tmp/build_66b113d2/vendor/bundle/ruby/3.0.0/gems/railties-5.1.6/lib/rails/application/finisher.rb:45:in `block in <module:Finisher>'
       /tmp/build_66b113d2/vendor/bundle/ruby/3.0.0/gems/railties-5.1.6/lib/rails/initializable.rb:30:in `instance_exec'
       /tmp/build_66b113d2/vendor/bundle/ruby/3.0.0/gems/railties-5.1.6/lib/rails/initializable.rb:30:in `run'
       /tmp/build_66b113d2/vendor/bundle/ruby/3.0.0/gems/railties-5.1.6/lib/rails/initializable.rb:59:in `block in run_initializers'
       /tmp/build_66b113d2/vendor/bundle/ruby/3.0.0/gems/railties-5.1.6/lib/rails/initializable.rb:58:in `run_initializers'
       /tmp/build_66b113d2/vendor/bundle/ruby/3.0.0/gems/railties-5.1.6/lib/rails/application.rb:353:in `initialize!'
       /tmp/build_66b113d2/config/environment.rb:5:in `<top (required)>'
       /tmp/build_66b113d2/vendor/bundle/ruby/3.0.0/gems/railties-5.1.6/lib/rails/application.rb:329:in `require'
       /tmp/build_66b113d2/vendor/bundle/ruby/3.0.0/gems/railties-5.1.6/lib/rails/application.rb:329:in `require_environment!'
       /tmp/build_66b113d2/vendor/bundle/ruby/3.0.0/gems/railties-5.1.6/lib/rails/application.rb:445:in `block in run_tasks_blocks'
       /tmp/build_66b113d2/vendor/bundle/ruby/3.0.0/gems/sprockets-rails-3.2.2/lib/sprockets/rails/task.rb:61: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

対処

チュートリアルの1.5.2には以下の注意書きがあった。

Rubyバージョン番号の削除(リスト 1.5)をしていない場合、ここでエラーが起こります。詳細は@jnchitoさんの記事『【初心者向け】RailsチュートリアルでHerokuデプロイ時に「Ruby 2.6.3はインストールできない」と言われたときの適切な対処方法』をご参照ください。

注意書き通りGemfileにはRubyバージョン番号を指定していないにも関わらず、エラーが発生している。
参考記事を見てみると、Herokuで使用できるRubyのバージョンは限られており、Ruby 2.6.3は使えないとのこと。
GemfileにはRubyのバージョンを指定しないことで、Heroku側が自動的にサポートしているバージョンを使ってくれるそう。

改めてHerokuのログを見てみると、Using Ruby version: ruby-3.0.3となっていることに気づく。
参考記事の執筆時期からHerokuの仕様が変わっており、自動で選択されるバージョンが手元の2.6.3と大きく乖離してしまったみたい。
(2022/3/15現在、サポートされているバージョンは2.6.9、2.7.5、3.0.3、3.1.1だった。最新のサポート状況は細かく確認したほうが良さそう。)

というわけで、Gemfile上でRubyバージョン番号に2.6.9を指定してみる。

Gemfile
source 'https://rubygems.org'

ruby '2.6.9' # 追記

gem 'rails',        '5.1.6'
gem 'puma',         '3.9.1'
gem 'sass-rails',   '5.0.6'
gem 'uglifier',     '3.2.0'
gem 'coffee-rails', '4.2.2'
gem 'jquery-rails', '4.3.1'
gem 'turbolinks',   '5.0.1'
gem 'jbuilder',     '2.7.0'

group :development, :test do
  gem 'sqlite3', '1.3.13'
  gem 'byebug',  '9.0.6', platform: :mri
end

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

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

念の為、手元の環境も揃えておく。

$ rvm install 2.6.9

結果

再度Herokuにデプロイし、うまくいった模様。(もっと新しいバージョン使えよ!と言われるけどね…)

-----> Building on the Heroku-20 stack
-----> Determining which buildpack to use for this app
 !     Warning: Multiple default buildpacks reported the ability to handle this app. The first buildpack in the list below will be used.
			Detected buildpacks: Ruby,Node.js
			See https://devcenter.heroku.com/articles/buildpacks#buildpack-detect-order
-----> Ruby app detected
-----> Installing bundler 1.17.3
-----> Removing BUNDLED WITH version in the Gemfile.lock
-----> Compiling Ruby/Rails
-----> Using Ruby version: ruby-2.6.6
-----> Installing dependencies using bundler 1.17.3

-----> Installing node-v16.13.1-linux-x64
-----> Detecting rake tasks
-----> Preparing app for Rails asset pipeline
       Running: rake assets:precompile
       Yarn executable was not detected in the system.
       Download Yarn at https://yarnpkg.com/en/docs/install
       I, [2022-03-12T06:39:49.590984 #1064]  INFO -- : Writing /tmp/build_df0e8262/public/assets/application-7e084e44b9a13db0cda25bad2ac6fdbbfe31462ec93176e245cd0bcbc079f436.js
       I, [2022-03-12T06:39:49.591525 #1064]  INFO -- : Writing /tmp/build_df0e8262/public/assets/application-7e084e44b9a13db0cda25bad2ac6fdbbfe31462ec93176e245cd0bcbc079f436.js.gz
       I, [2022-03-12T06:39:49.596353 #1064]  INFO -- : Writing /tmp/build_df0e8262/public/assets/application-e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855.css
       I, [2022-03-12T06:39:49.596444 #1064]  INFO -- : Writing /tmp/build_df0e8262/public/assets/application-e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855.css.gz
       Asset precompilation completed (2.21s)
       Cleaning assets
       Running: rake assets:clean
-----> Detecting rails configuration
###### WARNING:
       Detecting rails configuration failed
       set HEROKU_DEBUG_RAILS_RUNNER=1 to debug
###### WARNING:
       There is a more recent Ruby version available for you to use:
       
       2.6.9
       
       The latest version will include security and bug fixes. We always recommend
       running the latest version of your minor release.
       
       Please upgrade your Ruby version.
       
       For all available Ruby versions see:
         https://devcenter.heroku.com/articles/ruby-support#supported-runtimes
###### WARNING:
       No Procfile detected, using the default web server.
       We recommend explicitly declaring how to boot your server process via a Procfile.
       https://devcenter.heroku.com/articles/ruby-default-web-server
-----> Discovering process types
       Procfile declares types     -> (none)
       Default types for buildpack -> console, rake, web
-----> Compressing...
       Done: 55.7M
-----> Launching...
       Released v6
       https://mighty-plains-78424.herokuapp.com/ deployed to Heroku
5
1
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
1