Rails 6.1.7.10升级后出现uninitialized constant ActiveSupport错误求助
Rails升级后启动报错:uninitialized constant ActiveSupport::LoggerThreadSafeLevel::Logger
环境信息
- Rails版本:升级至6.1.7.10(原版本6.1.7.8)
- Ruby版本:2.6.6
错误信息
/home/cb/.gem/ruby/2.6.6/gems/activesupport-6.1.7.10/lib/active_support/logger_thread_safe_level.rb:16:in `module:LoggerThreadSafeLevel': uninitialized constant ActiveSupport::LoggerThreadSafeLevel::Logger (NameError)
错误回溯
... 14: from /home/cb/work/sb/config/environment.rb:2:in `<top (required)>' 13: from /home/cb/work/sb/config/environment.rb:2:in `require_relative' 12: from /home/cb/work/sb/config/application.rb:3:in `<top (required)>' 11: from /home/cb/work/sb/config/application.rb:3:in `require' 10: from /home/cb/.gem/ruby/2.6.6/gems/railties-6.1.7.10/lib/rails.rb:7:in `<top (required)>' 9: from /home/cb/.gem/ruby/2.6.6/gems/railties-6.1.7.10/lib/rails.rb:7:in `require' 8: from /home/cb/.gem/ruby/2.6.6/gems/activesupport-6.1.7.10/lib/active_support.rb:29:in `<top (required)>' 7: from /home/cb/.gem/ruby/2.6.6/gems/activesupport-6.1.7.10/lib/active_support.rb:29:in `require' 6: from /home/cb/.gem/ruby/2.6.6/gems/activesupport-6.1.7.10/lib/active_support/logger.rb:3:in `<top (required)>' 5: from /home/cb/.gem/ruby/2.6.6/gems/activesupport-6.1.7.10/lib/active_support/logger.rb:3:in `require' 4: from /home/cb/.gem/ruby/2.6.6/gems/activesupport-6.1.7.10/lib/active_support/logger_silence.rb:5:in `<top (required)>' 3: from /home/cb/.gem/ruby/2.6.6/gems/activesupport-6.1.7.10/lib/active_support/logger_silence.rb:5:in `require' 2: from /home/cb/.gem/ruby/2.6.6/gems/activesupport-6.1.7.10/lib/active_support/logger_thread_safe_level.rb:8:in `<top (required)>' 1: from /home/cb/.gem/ruby/2.6.6/gems/activesupport-6.1.7.10/lib/active_support/logger_thread_safe_level.rb:9:in `<module:ActiveSupport>' /home/cb/.gem/ruby/2.6.6/gems/activesupport-6.1.7.10/lib/active_support/logger_thread_safe_level.rb:16:in `<module:LoggerThreadSafeLevel>': uninitialized constant ActiveSupport::LoggerThreadSafeLevel::Logger (NameError)
补充说明
Rails控制台可正常使用,暂无法定位问题根源。
解决建议
- 排查gem依赖冲突:执行
bundle list查看是否存在多版本activesupport或logger类gem共存的情况,若有第三方gem锁定旧版本activesupport,尝试更新该gem或临时移除排查。 - 清理并重新安装gem:
- 执行
bundle clean --force清理未使用的gem - 删除项目根目录下的
Gemfile.lock文件 - 重新执行
bundle install确保所有gem版本匹配
- 执行
- 检查自定义Logger配置:查看项目中
config/application.rb、config/environments/*.rb或初始化文件里的自定义Logger代码,尝试注释掉相关配置后重启应用,确认是否为自定义逻辑导致的加载问题。 - 修复加载顺序问题:在
config/application.rb顶部添加require 'logger',确保Ruby标准库的Logger模块在ActiveSupport相关模块前加载。 - 验证Ruby环境完整性:尝试通过rbenv/rvm重新安装Ruby 2.6.6,排除Ruby环境损坏导致的异常。
内容的提问来源于stack exchange,提问作者Ross
相关产品推荐
相关产品推荐

