2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【Ruby on Rails】rails newがエラーになる

Last updated at Posted at 2025-01-20

発生した事象

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' <= この行を追記
(...省略...)
2
0
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
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?