LoginSignup
2
1

More than 1 year has passed since last update.

RubyInstaller 3.1.2-1はまずgem install bundlerしましょう

Last updated at Posted at 2022-08-18

言いたいことはタイトルで完了したので以下発生した問題と原因・解決方法です。

問題:rails newが通らない

ちょいと検証したいことがあってrails newしようと思い、devkitなしのバージョン入れてたことに気づいて(ネイティブライブラリビルドするgemがインストールエラーになって)、ついでなのでRubyInstallerでRuby 3.1.2を入れました。

で、rails newしたところ、bundle installは通ったもののその後の処理でエラーが出てしまいました。

       rails  importmap:install
rails aborted!
TZInfo::DataSourceNotFound: tzinfo-data is not present. Please add gem 'tzinfo-data' to your Gemfile and run bundle install
C:/TEMP/sample_app/config/environment.rb:5:in `<main>'

Caused by:
TZInfo::DataSources::ZoneinfoDirectoryNotFound: None of the paths included in TZInfo::DataSources::ZoneinfoDataSource.search_path are valid zoneinfo directories.
C:/TEMP/sample_app/config/environment.rb:5:in `<main>'
Tasks: TOP => app:template => environment
(See full trace by running task with --trace)
       rails  turbo:install stimulus:install
You must either be running with node (package.json) or importmap-rails (config/importmap.rb) to use this gem.
You must either be running with node (package.json) or importmap-rails (config/importmap.rb) to use this gem.

tzinfo-dataが入ってない?そんなわけないやろと思いましたが、そんなわけありました。ちなみにtzinfo-dataをインストールするためのGemfileの記述は以下のようになっています。

Gemfile抜粋
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem "tzinfo-data", platforms: %i[ mingw mswin x64_mingw jruby ]

原因その1:platform文字列の変更

実はRubyInstallerは3.1.0からUCRTを使うようになっており、platform文字列がx64-mingw-ucrtに変更されています。

「x64-mingw」の個所だけ見てマッチしてくれそうですがそうは問屋が卸しませんでした。

原因その2:Ruby 3.1.2同梱のbundlerではx64-mingw-ucrtに未対応

同梱されているbundlerは2.3.7です。というわけで2.3.7の「platformはx64_mingwかい?」と調べている箇所を見てみましょう。ってrubygemsの下に移動したからbundlerのバージョンを固定してみる方法がわからん。ともかく問題の部分です。

bundler/current_ruby.rb
    def x64_mingw?
      Gem.win_platform? && Bundler.local_platform != Gem::Platform::RUBY && Bundler.local_platform.os == "mingw32" && Bundler.local_platform.cpu == "x64"
    end

おわかりいただけただろうか。
"mingw32"と等価比較をしているのである!
というわけで「x64-mingwの部分だけ見てるんちゃうん?」という疑問については、「ちゃいまっせー」でした。昔誰かが「プログラムは期待するようには動かない。書いてある通りに動く」って言ってた気がします。

余談ですが、「x64」で「mingw32」っての変だよなーとはずっと思ってたのですが互換性のため?に「mingw32」としていたのを今回思い切って32をなくした?ら影響があったってプログラミングあるあるな感じですね:scream:

解決方法

さてわざわざ問題があるコードを先に見せたことからわかると思いますが、最新版ではちゃんと直ってます。
って、6/29って、3.1リリースしてから半年も経ってるやん。ひょっとして誰もWindowsでRails開発してない?(私はしてます)

タイトルに書いたようにbundler自体を更新しましょう。

>gem install bundler
Fetching bundler-2.3.20.gem
Successfully installed bundler-2.3.20
Parsing documentation for bundler-2.3.20
Installing ri documentation for bundler-2.3.20
Done installing documentation for bundler after 0 seconds
1 gem installed

>bundler -v
Bundler version 2.3.20

今度は先ほどのエラーが起こることなくrails newが完了します。

2
1
2

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
2
1