発生した事象
2025年1月20日、rails 6.1.7.7 でrails new
した時にエラーになった。
❯ rails new test_app -d postgresql
~/.rbenv/versions/3.3.6/lib/ruby/gems/3.3.0/gems/activesupport-6.1.7.10/lib/active_support/logger_thread_safe_level.rb:16:in `<module:LoggerThreadSafeLevel>': uninitialized constant ActiveSupport::LoggerThreadSafeLevel::Logger (NameError)
Logger::Severity.constants.each do |severity|
^^^^^^
原因
上記のスレッドにあるとおり、concurrent-rubyというgemのv1.3.5(2025年1月16日リリース)に入った変更が原因だった。
解決策
既存のrailsプロジェクトで、Gemfile
が存在する場合は、下記の記述を追加してconcurrent-rubyのバージョンを1.3.4にロックすればよい。
Gemfile
(...省略...)
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails', branch: 'main'
gem 'rails', '~> 6.1.7', '>= 6.1.7.10'
# Use concurrent-ruby v1.3.4
gem 'concurrent-ruby', '1.3.4' <= この行を追記
(...省略...)
rails new
前でGemfileが存在しない場合は、先にbundle init
でGemfileを作成し、concurrent-rubyのバージョンをv.1.3.4にロックしてから、rails new
するとうまくいった。
mkdir my_app
cd my_app
bundle init
=> Gemfileができる
echo "gem 'rails', '~> 6.1.7', '>= 6.1.7.7'" >> Gemfile
echo "gem 'concurrent-ruby', '1.3.4'" >> Gemfile
cat Gemfile
=> Gemfileに上記のrails, concurrent-rubyのバージョン指定が追記されていることを確認する
bundle exec rails _6.1.7.7_ new .
=> 途中でGemfileがconflictしているが上書きするか?と聞かれるので、Y(上書きする)で進む
以上でrailsアプリが作成された。
最後に念のため、生成されたGemfile
にconcurrent-rubyのバージョンロックを追加した。
Gemfile
(...省略...)
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails', branch: 'main'
gem 'rails', '~> 6.1.7', '>= 6.1.7.10'
# Use concurrent-ruby v1.3.4
gem 'concurrent-ruby', '1.3.4' <= この行を追記
(...省略...)