{"record":{"id":"c9cb87104c0c16d4","repo":"voormedia/rails-erd","slug":"the-ruby-graphviz-gem-is-required-for-graphviz-out","errorCode":null,"errorMessage":"The ruby-graphviz gem is required for Graphviz output. Add `gem 'ruby-graphviz'` to your Gemfile, or use `generator: mermaid` instead.","messagePattern":"The ruby-graphviz gem is required for Graphviz output\\. Add `gem 'ruby-graphviz'` to your Gemfile, or use `generator: mermaid` instead\\.","errorType":"exception","errorClass":"LoadError","httpStatus":null,"severity":"error","filePath":"lib/rails_erd/diagram/graphviz.rb","lineNumber":191,"sourceCode":"            options[:arrowtail] = relationship.many_to? ? \"vee\" : \"none\"\n\n            ranges = [relationship.cardinality.destination_range, relationship.cardinality.source_range].map do |range|\n              if range.min == range.max\n                \"#{range.min}\"\n              else\n                \"#{range.min}..#{range.max == Domain::Relationship::N ? \"∗\" : range.max}\"\n              end\n            end\n            options[:headlabel], options[:taillabel] = *ranges\n          end\n        end\n      end\n\n      attr_accessor :graph\n\n      setup do\n        unless defined?(GraphViz)\n          raise LoadError, \"The ruby-graphviz gem is required for Graphviz output. \" \\\n            \"Add `gem 'ruby-graphviz'` to your Gemfile, or use `generator: mermaid` instead.\"\n        end\n\n        self.graph = GraphViz.digraph(domain.name)\n\n        # Set all default attributes.\n        GRAPH_ATTRIBUTES.each { |attribute, value| graph[attribute] = value }\n        NODE_ATTRIBUTES.each  { |attribute, value| graph.node[attribute] = value }\n        EDGE_ATTRIBUTES.each  { |attribute, value| graph.edge[attribute] = value }\n\n        # Switch rank direction if we're creating a vertically oriented graph.\n        graph[:rankdir] = (options.orientation == \"vertical\") ? :LR : :TB\n\n        # Title of the graph itself.\n        graph[:label] = \"#{title}\\\\n\\\\n\" if title\n\n        # Style of splines\n        graph[:splines] = options.splines unless options.splines.nil?","sourceCodeStart":173,"sourceCodeEnd":209,"githubUrl":"https://github.com/voormedia/rails-erd/blob/dae6e52018c94ff6d3e3bb0fdbc2cb0c680ec165/lib/rails_erd/diagram/graphviz.rb#L173-L209","documentation":"rails-erd's Graphviz generator needs the ruby-graphviz gem to build diagrams. Since v2.0 the gem is optional: the require at the top of lib/rails_erd/diagram/graphviz.rb is wrapped in begin/rescue LoadError, so the failure is deferred to diagram generation, where the setup callback finds no GraphViz constant (defined?(GraphViz) is false, graphviz.rb:189-193) and raises LoadError with install instructions. It means the process running 'rake erd' or RailsERD::Diagram::Graphviz.create has no ruby-graphviz loaded.","triggerScenarios":"Running the default Graphviz generator -- 'rake erd', RailsERD::Diagram::Graphviz.create(options), or Graphviz.new(domain).create -- in a process where require 'graphviz' failed: gem absent from the Gemfile, present but never installed (no bundle install), or generator switched back to :graphviz after runs with generator: :mermaid.","commonSituations":"Upgrading rails-erd from 1.x (ruby-graphviz was a hard dependency) to 2.x where it became optional; fresh clones or CI images that never bundle the optional gem; mixing up gem names (gem 'graphviz' vs gem 'ruby-graphviz'); switching an erd config back to the default generator on a machine that only ever installed deps for mermaid output.","solutions":["Add gem 'ruby-graphviz' to your Gemfile (the gem is named ruby-graphviz, the require is 'graphviz') and run bundle install","Verify it loads in the same context: bundle exec ruby -e \"require 'graphviz'; puts defined?(GraphViz)\"","If you cannot add the gem, switch generators: rake erd generator=mermaid (or RailsERD.options[:generator] = :mermaid), which is pure Ruby and needs no extra gem"],"exampleFix":"# before (Gemfile)\ngem 'rails-erd'\n# $ bundle exec rake erd\n# => LoadError: The ruby-graphviz gem is required for Graphviz output...\n\n# after (Gemfile)\ngem 'rails-erd'\ngem 'ruby-graphviz'\n# $ bundle install && bundle exec rake erd","handlingStrategy":"validation","validationCode":"begin\n  require 'graphviz'\nrescue LoadError\n  # fall back before ever touching the Graphviz diagram\nend\n\nRailsERD::Diagram::Graphviz.create if defined?(GraphViz)","typeGuard":"def graphviz_available?\n  defined?(GraphViz) == 'constant'\nend","tryCatchPattern":"begin\n  RailsERD::Diagram::Graphviz.create\nrescue LoadError => e\n  warn e.message\n  RailsERD::Diagram::Mermaid.create\nend","preventionTips":["Declare ruby-graphviz in the Gemfile wherever generator: :graphviz is the default","Preflight CI with bundle exec ruby -e \"require 'graphviz'\" before the erd rake task","Remember the gem name is ruby-graphviz but the require is 'graphviz'"],"tags":["ruby","rails-erd","ruby-graphviz","gem","loaderror","bundler"],"backgroundTag":"missing-ruby-gem","analyzedSha":"dae6e52018c94ff6d3e3bb0fdbc2cb0c680ec165","analyzedAt":"2026-08-23T02:52:18.679Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}