Just do IT

思うは招く

dependency tzinfo-data (>= 0) will be unused by any of the platforms Bundler is installing for の対処

問題

環境

railsbundle installをするとこんなメッセージが出た。

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`.

エラーではないためコマンドは実行されるのだが、毎回出てくるので邪魔。

解決

以下の記事を参考に解決した。

このgemの開発者自身が解決策を説明している。

"The dependency tzinfo-data will be unused" on Ubuntu · Issue #12 · tzinfo/tzinfo-data

ただし上記記事は英語なので日本語がいい方はこちらを。

特に「bundle installする際のtzinfo-dataのwarningがウザい - Qiita」には詳しく解説があるので読むことをおすすめ。

方法1

Gemfileの以下の部分を、

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

次のように変更。

gem 'tzinfo-data'

platforms: [:mingw, :mswin, :x64_mingw, :jruby]を削除。

その後、bundle update

bundle update

MacOS環境ではこれで解決した。

ただし、vagrant + Ubuntu 環境だとこれをしたらエラーが出た。

方法2

ワーニングメッセージにあるように、以下コマンドを実行する。

bundle lock --add-platform x86-mingw32 x86-mswin32 x64-mingw32 java

vagrant + Ubuntu 環境下だとこれで解決した。

原因

開発者によると、

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.

このgemを使う理由は、Windowsタイムゾーン情報を取得するためやねん。せやから、UbuntuとかUnixベースのOSなら使う必要ないで。

つまり、UnixベースのMacOSUbuntuDebianなどで開発をする場合は消し去ってもいいとのこと。