mermaid-js/mermaid · error
Edges array is required in layout data
Error message
Edges array is required in layout data
What it means
Thrown by validateLayoutData when data.edges is present but not an array. Note executeTidyTreeLayout tolerates missing/non-array edges by defaulting them to [], so this validator is stricter than the layout entry point and exists for callers that want guaranteed-correct shapes.
Source
Thrown at packages/mermaid-layout-tidy-tree/src/layout.ts:649
* Validate layout data structure
* @param data - The data to validate
* @returns True if data is valid, throws error otherwise
*/
export function validateLayoutData(data: LayoutData): boolean {
if (!data) {
throw new Error('Layout data is required');
}
if (!data.config) {
throw new Error('Configuration is required in layout data');
}
if (!Array.isArray(data.nodes)) {
throw new Error('Nodes array is required in layout data');
}
if (!Array.isArray(data.edges)) {
throw new Error('Edges array is required in layout data');
}
return true;
}
View on GitHub (pinned to d93e9c88c0)
Solutions
- Coerce edges to an array: Object.values(edges) or [] when none exist.
- Use Array.isArray(edges) at the producer and convert before assembling LayoutData.
- If you do not need strict validation, skip validateLayoutData and rely on executeTidyTreeLayout's lenient defaulting.
Example fix
// before
validateLayoutData({ nodes, edges: edgesRecord, config });
// after
validateLayoutData({ nodes, edges: Object.values(edgesRecord), config }); Defensive patterns
Strategy: type-guard
Validate before calling
if (!Array.isArray(data.edges)) {
data.edges = [];
}
validateLayoutData(data); Type guard
function hasEdgeArray(data: unknown): data is { edges: unknown[] } {
return Array.isArray((data as any).edges);
} Prevention
- Default edges to [] when assembling LayoutData.
- Coerce record/object edge stores to arrays at the producer boundary.
When it happens
Trigger: Passing data.edges as an object, a single edge, or any non-array value while still calling the strict validator.
Common situations: Producer modeled edges as a keyed object and forwarded it; a serialization step left edges as a string; defensive validation turned on before the layout call.
Related errors
- Nodes array is required in layout data
- No nodes found in layout data
- Layout data is required
- Configuration is required in layout data
- An align directive requires at least two members; got ${hint
AI-assisted analysis of mermaid-js/mermaid@d93e9c88c0 (2026-08-12).
Data as JSON: /api/errors/6b1917394dd30389.
Report an issue: GitHub.