Windows下Rails引入bootsnap触发Win32::Resolv方法未定义错误
解决Windows下Rails添加bootsnap后出现的Win32::Resolv NoMethodError问题
问题原因
你遇到的错误是因为eventmachine 1.2.7版本和Ruby 3.3不兼容。Ruby 3.3对Win32::Resolv模块做了调整,移除了get_hosts_path方法,但旧版eventmachine仍在调用这个已被移除的方法,导致报错。
解决方案
1. 升级eventmachine到兼容版本
这是最稳妥的解决方式:
- 打开项目的
Gemfile,修改eventmachine的版本声明:gem 'eventmachine', '>= 1.2.8' - 执行命令更新依赖:
bundle update eventmachine
2. 临时补全缺失方法(应急用)
如果暂时无法升级eventmachine,可以手动给Win32::Resolv模块添加缺失的方法,再加载bootsnap:
修改config/boot.rb的代码顺序为:
# 先补全方法 module Win32 module Resolv def self.get_hosts_path File.join(ENV['SystemRoot'], 'System32', 'drivers', 'etc', 'hosts') end end end # 再加载bootsnap require 'bootsnap/setup'
3. 确保bootsnap版本兼容
同时建议更新bootsnap到最新稳定版,避免其他兼容性问题:
bundle update bootsnap
内容的提问来源于stack exchange,提问作者Richard_G
相关产品推荐
相关产品推荐

