LoginSignup
80
60

More than 3 years have passed since last update.

bundle installする際のtzinfo-dataのwarningがウザい

Posted at

問題のエラーメッセージ

The dependency tzinfo-data (>= 0) will be unused by any of the platforms Bundler is installing for. Bundler is installing for ruby but the dependency is only for x86-mingw32, x86-mswin32, x64-mingw32, java. To add those platforms to the bundle, run `bundle lock --add-platform x86-mingw32 x86-mswin32 x64-mingw32 java`.

bundle install実行時に毎回上記warningが出ていたのだが、面倒なので後回しにしていた。
そろそろ重い腰を上げて調査・対処してみる。

実行環境

macOS Mojave 10.14.6
Ruby 2.6.1
Rails 6.0.1
Bundler 2.0.2

問題の原因

Railsアプリを作成した時にGemfileに書かれる下記行がwarningの原因。

gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]

tzinfo-dataTZInfoが参照するタイムゾーン情報を提供するgem。
TZInfoはRubyからタイムゾーン情報を参照し、その情報に基づいて時間をコンバートするためのライブラリ。

解決方法

この問題についてググってみると、githubのtzinfo-dataの作者のコメントに解決方法が書いてあった。

解決方法は4つあって下記のいずれかを実行すれば良い。

  1. Gemfileのtzinfo-data行のplatforms: [:mingw, :mswin, :x64_mingw, :jruby]を削除し、bundle updateを実行。プラットフォーム関係なくtzinfo-dataのタイムゾーンを参照する設定。

  2. Gemfileからtzinfo-data行を削除。tzinfo-dataではなくシステムのタイムゾーンを参照するようになる。Windowsの場合は、tzinfo-dataを削除すると、TZInfo::DataSourceNotFound例外が発生してしまう。

  3. bundle lock --add-platform mingw, mswin, x64_mingw, jrubyを実行。Gemfile.lockに依存プラットフォーム情報を記述してしまう方法。

  4. bundle config --local disable_platform_warnings trueを実行(Bundlerのバージョンが1.17.0以上であることが必須)。Bundler自体のwarningを出させないようにする設定。

4はカレントディレクトリのRailsアプリにだけ適用する方法で、システムのカレントユーザに対して非表示にしたければ、下記のように--localを省いて実行すればOK!

bundle config disable_platform_warnings true

Gemfileにtzinfo-dataを指定している理由

解決方法と同じく、githubのtzinfo-dataの作者のコメントに書いてある。

The purpose of this line is to include the tzinfo-data gem in the bundle on Windows to act as a source of time zone data. This gem is unnecessary on Ubuntu (and Unix-based systems in general) because the system includes time zone data that can be read directly by tzinfo.

コメントによると、Windowsでタイムゾーン情報を取得することを目的として、tzinfo-dataを入れているらしい。Windowsでtzinfo-dataを削除すると例外が発生するのは、tzinfo-dataがないとタイムゾーン情報が取得できないからのようだ。
そもそもUnixベースのOSではtzinfoからシステムのタイムゾーン情報に直接アクセスできるので、このgemを入れる必要はないそう。

80
60
0

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
80
60