{"record":{"id":"1986b4e3ff6d5481","repo":"mermaid-js/mermaid","slug":"there-can-be-only-one-root-no-parent-could-be-fou","errorCode":null,"errorMessage":"There can be only one root. No parent could be found for (\"${node.descr}\")","messagePattern":"There can be only one root\\. No parent could be found for \\(\"(.+?)\"\\)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/mermaid/src/diagrams/mindmap/mindmapDb.ts","lineNumber":120,"sourceCode":"      nodeId: sanitizeText(id, conf),\n      level,\n      descr: sanitizeText(descr, conf),\n      type,\n      children: [],\n      width: conf.mindmap?.maxNodeWidth ?? defaultConfig.mindmap.maxNodeWidth,\n      padding,\n      isRoot,\n    };\n\n    const parent = this.getParent(level);\n    if (parent) {\n      parent.children.push(node);\n      this.nodes.push(node);\n    } else {\n      if (isRoot) {\n        this.nodes.push(node);\n      } else {\n        throw new Error(\n          `There can be only one root. No parent could be found for (\"${node.descr}\")`\n        );\n      }\n    }\n  }\n\n  public getType(startStr: string, endStr: string) {\n    log.debug('In get type', startStr, endStr);\n    switch (startStr) {\n      case '[':\n        return this.nodeType.RECT;\n      case '(':\n        return endStr === ')' ? this.nodeType.ROUNDED_RECT : this.nodeType.CLOUD;\n      case '((':\n        return this.nodeType.CIRCLE;\n      case ')':\n        return this.nodeType.CLOUD;\n      case '))':","sourceCodeStart":102,"sourceCodeEnd":138,"githubUrl":"https://github.com/mermaid-js/mermaid/blob/d93e9c88c01a599c062ee6a3f1462e3558ac6b90/packages/mermaid/src/diagrams/mindmap/mindmapDb.ts#L102-L138","documentation":"Thrown by addNode in the mindmap db when a non-root node cannot find a parent at level-1 via getParent. Mindmaps require exactly one root node; every other node must have a parent one level shallower. If a node is declared at a depth with no existing ancestor at depth-1, and it is not itself the root, the tree is malformed and the build aborts.","triggerScenarios":"Indenting a node two levels deeper than its parent (skipping a level); declaring a second root-level node; starting the mindmap body with a deeply indented node before any root.","commonSituations":"Using tabs vs spaces inconsistently so the parser computes wrong levels; copy-pasting subtrees that reference a parent indentation you didn't copy; author forgetting the single top-level root node.","solutions":["Ensure exactly one node sits at the top level (the root) and every other node is indented exactly one level deeper than its parent.","Normalize indentation to consistent spaces and verify no level is skipped.","Start the mindmap with the root node on its own line, then add children one indent level at a time.","If nesting deeply, build incrementally and render after each level to catch the error early."],"exampleFix":"// before — child jumps two levels, no intermediate parent\nmindmap\n  root\n      deeply_nested_child\n\n// after\nmindmap\n  root\n    child\n      deeply_nested_child","handlingStrategy":"validation","validationCode":"// Validate mindmap tree depth: each node's level may be at most parentLevel+1.\nfunction validateMindmapDepth(nodes: {level:number;descr:string}[]): string[] {\n  const errors: string[] = [];\n  let prevLevel = nodes[0]?.level ?? 0;\n  for (const n of nodes.slice(1)) {\n    if (n.level > prevLevel + 1) {\n      errors.push(`Node '${n.descr}' skips a level (got ${n.level}, expected <= ${prevLevel + 1})`);\n    }\n    prevLevel = n.level;\n  }\n  return errors;\n}","typeGuard":null,"tryCatchPattern":"try {\n  await mermaid.render('g', diagramText);\n} catch (e) {\n  if (e instanceof Error && /There can be only one root/.test(e.message)) {\n    showUserError('Your mindmap has a node with no parent. Ensure exactly one root and indent children one level at a time.');\n  } else {\n    throw e;\n  }\n}","preventionTips":["Declare exactly one root node at the top level.","Indent each child exactly one level deeper than its parent — never skip a level.","Use consistent spacing for indentation."],"tags":["mermaid","mindmap","parsing","data-integrity"],"backgroundTag":null,"analyzedSha":"d93e9c88c01a599c062ee6a3f1462e3558ac6b90","analyzedAt":"2026-08-12T06:23:11.304Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}