mermaid-js/mermaid · error

No nodes found in layout data

Error message

No nodes found in layout data

What it means

Thrown by executeTidyTreeLayout when the supplied LayoutData has no usable nodes array (undefined, not an array, or zero-length). The tidy-tree algorithm is built around a node hierarchy, so an empty node set gives it nothing to lay out and it aborts before any geometry work. The check runs inside a Promise executor, so the error is delivered as a rejection rather than a synchronous throw.

Source

Thrown at packages/mermaid-layout-tidy-tree/src/layout.ts:29

} from './types.js';

/**
 * Execute the tidy-tree layout algorithm on generic layout data
 *
 * This function takes layout data and uses the non-layered-tidy-tree-layout
 * algorithm to calculate optimal node positions for tree structures.
 *
 * @param data - The layout data containing nodes, edges, and configuration
 * @param config - Mermaid configuration object
 * @returns Promise resolving to layout result with positioned nodes and edges
 */
export function executeTidyTreeLayout(data: LayoutData): Promise<LayoutResult> {
  let intersectionShift = 50;

  return new Promise((resolve, reject) => {
    try {
      if (!data.nodes || !Array.isArray(data.nodes) || data.nodes.length === 0) {
        throw new Error('No nodes found in layout data');
      }

      if (!data.edges || !Array.isArray(data.edges)) {
        data.edges = [];
      }

      const { leftTree, rightTree, rootNode } = convertToDualTreeFormat(data);

      const gap = 20;
      const bottomPadding = 40;
      intersectionShift = 30;

      const bb = new BoundingBox(gap, bottomPadding);
      const layout = new Layout(bb);

      let leftResult = null;
      let rightResult = null;

View on GitHub (pinned to d93e9c88c0)

Solutions

  1. Ensure data.nodes is a non-empty array before invoking executeTidyTreeLayout.
  2. Trace the upstream producer of LayoutData and confirm it actually emits nodes.
  3. Guard the call site with validateLayoutData(data) plus a length check.
  4. If an empty graph is legitimately possible, short-circuit with an empty LayoutResult instead of calling the layout function.

Example fix

// before
const result = await executeTidyTreeLayout(data);

// after
if (!data.nodes?.length) {
  return { nodes: [], edges: [] } satisfies LayoutResult;
}
const result = await executeTidyTreeLayout(data);
Defensive patterns

Strategy: validation

Validate before calling

import { validateLayoutData } from 'mermaid-layout-tidy-tree';

function hasNodes(data: unknown): data is { nodes: unknown[] } {
  return !!data && Array.isArray((data as any).nodes) && (data as any).nodes.length > 0;
}

// before layout
validateLayoutData(data);
if (!hasNodes(data)) {
  throw new Error('Cannot layout: no nodes provided');
}

Type guard

function isLayoutable(data: unknown): data is { nodes: unknown[]; edges: unknown[]; config: unknown } {
  return !!data
    && !!(data as any).config
    && Array.isArray((data as any).nodes) && (data as any).nodes.length > 0
    && Array.isArray((data as any).edges);
}

Try / catch

try {
  const result = await executeTidyTreeLayout(data);
} catch (e) {
  if (e instanceof Error && /No nodes found/.test(e.message)) {
    // supply empty result or report upstream
  } else throw e;
}

Prevention

When it happens

Trigger: Calling executeTidyTreeLayout({nodes:[], edges:[]}); calling it with nodes omitted or set to null; passing a LayoutData object whose nodes were filtered down to nothing upstream.

Common situations: An upstream diagram parser produced zero nodes (e.g. an empty mindmap/stateDiagram), a graph extraction step filtered out all nodes by accident, or the layout package is wired in but no real graph data was generated before layout.

Related errors


AI-assisted analysis of mermaid-js/mermaid@d93e9c88c0 (2026-08-12). Data as JSON: /api/errors/e3214569fec59ef9. Report an issue: GitHub.