mermaid-js/mermaid · error
No nodes available to create tree
Error message
No nodes available to create tree
What it means
Thrown by convertToDualTreeFormat when it cannot find a root node AND nodes.length === 0. In practice this is a defensive duplicate of the empty-nodes guard at line 28: executeTidyTreeLayout already rejects empty nodes before calling convertToDualTreeFormat, so reaching this throw requires calling convertToDualTreeFormat directly (it is a private, non-exported helper) with an empty array.
Source
Thrown at packages/mermaid-layout-tidy-tree/src/layout.ts:108
const children = new Map<string, string[]>();
const parents = new Map<string, string>();
edges.forEach((edge) => {
const parentId = edge.start;
const childId = edge.end;
if (parentId && childId) {
if (!children.has(parentId)) {
children.set(parentId, []);
}
children.get(parentId)!.push(childId);
parents.set(childId, parentId);
}
});
const rootNodeData = nodes.find((node) => !parents.has(node.id));
if (!rootNodeData && nodes.length === 0) {
throw new Error('No nodes available to create tree');
}
const actualRoot = rootNodeData ?? nodes[0];
const rootNode: TidyTreeNode = {
id: actualRoot.id,
width: actualRoot.width ?? 100,
height: actualRoot.height ?? 50,
_originalNode: actualRoot,
};
const rootChildren = children.get(actualRoot.id) ?? [];
const leftChildren: string[] = [];
const rightChildren: string[] = [];
rootChildren.forEach((childId, index) => {
if (index % 2 === 0) {
leftChildren.push(childId);View on GitHub (pinned to d93e9c88c0)
Solutions
- Do not call convertToDualTreeFormat directly; use executeTidyTreeLayout.
- If testing the helper internally, supply at least one node.
- Treat a real occurrence as a sign that the earlier guard in executeTidyTreeLayout was bypassed.
Defensive patterns
Strategy: validation
Validate before calling
// Ensure convertToDualTreeFormat is never reached with empty nodes:
if (!data.nodes || data.nodes.length === 0) {
throw new Error('Skipping layout: no nodes');
}
const result = await executeTidyTreeLayout(data); Type guard
function hasAtLeastOneNode(data: unknown): data is { nodes: { id: string }[] } {
return Array.isArray((data as any).nodes) && (data as any).nodes.length > 0;
} Prevention
- Never call the private convertToDualTreeFormat helper directly.
- Keep the public executeTidyTreeLayout as the sole entry point so its guard always runs first.
When it happens
Trigger: Only reachable if convertToDualTreeFormat is invoked with a zero-length nodes array outside the normal executeTidyTreeLayout entry path. Through the public API, error [0] fires first and this branch is never reached.
Common situations: Almost never seen by external callers; surfaces only during internal refactors or tests that call convertToDualTreeFormat directly with stubbed data.
Related errors
- No nodes found in layout data
- Nodes array is required in layout data
- Layout data is required
- Configuration is required in layout data
- Edges array is required in layout data
AI-assisted analysis of mermaid-js/mermaid@d93e9c88c0 (2026-08-12).
Data as JSON: /api/errors/151fc6be7e7703d0.
Report an issue: GitHub.