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

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.29 03:17:34