{"record":{"id":"ffffc6d6e11e0331","repo":"mermaid-js/mermaid","slug":"root-node-is-required","errorCode":null,"errorMessage":"Root node is required","messagePattern":"Root node is required","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/mermaid/src/rendering-util/layout-algorithms/cose-bilkent/layout.ts","lineNumber":65,"sourceCode":"  }\n}\n\n/**\n * Validate layout data structure\n * @param data - The data to validate\n * @returns True if data is valid, throws error otherwise\n */\nexport function validateLayoutData(data: LayoutData): boolean {\n  if (!data) {\n    throw new Error('Layout data is required');\n  }\n\n  if (!data.config) {\n    throw new Error('Configuration is required in layout data');\n  }\n\n  if (!data.rootNode) {\n    throw new Error('Root node is required');\n  }\n\n  if (!data.nodes || !Array.isArray(data.nodes)) {\n    throw new Error('No nodes found in layout data');\n  }\n\n  if (!Array.isArray(data.edges)) {\n    throw new Error('Edges array is required in layout data');\n  }\n\n  return true;\n}\n","sourceCodeStart":47,"sourceCodeEnd":78,"githubUrl":"https://github.com/mermaid-js/mermaid/blob/d93e9c88c01a599c062ee6a3f1462e3558ac6b90/packages/mermaid/src/rendering-util/layout-algorithms/cose-bilkent/layout.ts#L47-L78","documentation":"Third guard in validateLayoutData: `data` and `data.config` are present but `data.rootNode` is missing. cose-bilkent is a force-directed layout rooted at a primary node (used for mindmap-like layouts), so a rootNode is mandatory. Thrown at layout.ts:65.","triggerScenarios":"A LayoutData whose graph has no designated root, e.g. { config, nodes, edges } with rootNode undefined. Happens if the diagram type routed to cose-bilkent doesn't compute a root (the layout expects one to anchor the layout tree).","commonSituations":"Routing a diagram type that has no natural root (e.g. a generic flowchart) to cose-bilkent, or a bug in the diagram-db layer that fails to assign rootNode from the parsed AST. cose-bilkent is opt-in (includeLargeFeatures) so this usually surfaces in custom integrations.","solutions":["Ensure the diagram-db transform sets data.rootNode to the central/root node id before layout.","If using cose-bilkent directly, designate one node as root in the LayoutData you construct.","Use the dagre layout for diagrams without a clear root (cose-bilkent is root-dependent).","Log data.rootNode to confirm it is set and references an existing node id."],"exampleFix":"// before\n{ config, nodes, edges, layoutAlgorithm: 'cose-bilkent' }\n// after\n{ config, nodes, edges, layoutAlgorithm: 'cose-bilkent', rootNode: nodes[0].id }","handlingStrategy":"validation","validationCode":"if (!data?.rootNode) throw new Error('LayoutData.rootNode missing — designate a root node');","typeGuard":"function hasRootNode(d: any): d is { rootNode: string } { return typeof d?.rootNode === 'string' && d.rootNode.length > 0; }","tryCatchPattern":"try { validateLayoutData(data); } catch (e) { if (/Root node is required/.test(String(e))) { data.rootNode = data.nodes[0]?.id; validateLayoutData(data); } else throw e; }","preventionTips":["Ensure the diagram-db transform sets rootNode.","Use dagre for root-less graphs; cose-bilkent needs a root.","Validate rootNode references an existing node id."],"tags":["layout","cose-bilkent","validation","graph"],"backgroundTag":null,"analyzedSha":"d93e9c88c01a599c062ee6a3f1462e3558ac6b90","analyzedAt":"2026-08-12T06:23:11.304Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}