ruby 运行dockerfile-rails gem时出错:未定义JSON:Module的方法“load_file”(NoMethodError)

2guxujil  于 2023-08-04  发布在  Ruby
关注(0)|答案(1)|浏览(98)

我正在使用这个Ruby on Rails gem,名为dockerfile-rails,尝试在我的应用中生成一个dockerfile,但它只是抛出了一个错误,将一个空的Dockerfile添加到我的根目录:
我运行了命令bundle add dockerfile-rails --optimistic --group development在他们的文档中描述,我可以看到gem "dockerfile-rails", ">= 1.5", :group => :development在Gemfile中,但是当我尝试运行bin/rails generate dockerfile时,我在终端中得到了一个错误:

block in api_client_dir': undefined method 'load_file' for JSON:Module (NoMethodError)

字符串
有人知道哪里出了问题吗?我使用ruby -v 2.7.2p137和Rails -v 7.0.6

cetgtptt

cetgtptt1#

这是dockerfile-rails gem中的一个bug。有几种解决方案:
1.更新你的Ruby版本到>= 3.0 -这个问题不会在这个版本上发生。
1.向dockerfile-rails报告问题,等待修复。
1.对JSON模块应用合理的补丁,如下所示:

module JSON
  module_function
  def load_file(filespec, opts = {})
    parse(File.read(filespec), opts)
  end
end

字符串
在dockerfile-rails加载之前。
1.从Gemfile中注解或删除vite-ruby,生成Dockerfile,然后取消注解vite ruby

相关问题