You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

执行rails assets:precompile遇LoadError:无法加载i18n/core_ext/hash

修复资产预编译时的i18n加载错误

1. 锁定兼容的i18n版本

报错提示找不到i18n/core_ext/hash,说明当前使用的i18n 1.6.0已移除该文件,而chewy 5.2.0仍依赖它。可以将i18n版本锁定到保留该文件的1.4.x系列:
在Gemfile中添加:

gem 'i18n', '~> 1.4.0'

执行bundle update i18n更新依赖后重新构建镜像。

2. 降级Bundler版本

日志中大量Bundler常量重复初始化的警告,说明Bundler 2.4.6与Ruby 2.6.0、Rails 5.2.x兼容性不佳。老项目建议使用适配的低版本Bundler,比如1.17.x:

  • 在Dockerfile中修改Bundler安装命令:
RUN gem install bundler -v 1.17.3
  • 执行bundle _1.17.3_ install更新Gemfile.lock顶部的BUNDLED WITH版本。

3. 优化资产预编译命令

直接在项目目录执行命令,并指定生产环境减少不必要的gem加载:

# Precompile assets
WORKDIR /opt/mastodon
RUN OTP_SECRET=precompile_placeholder SECRET_KEY_BASE=precompile_placeholder RAILS_ENV=production rails assets:precompile

4. 调整chewy gem版本

chewy 5.2.0与当前依赖组合存在兼容问题,可尝试降级到适配Rails 5.2.x的版本:
在Gemfile中修改:

gem 'chewy', '~> 5.0.0'

执行bundle update chewy更新依赖。


内容的提问来源于stack exchange,提问作者alilland

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.01 15:45:23