mermaid-js/mermaid · error · Error
Edges array is required in layout data
Error message
Edges array is required in layout data
What it means
Fifth and final guard in validateLayoutData: `data.edges` is present but not an array (an undefined edges field also triggers it, since Array.isArray(undefined) is false). The cose-bilkent layout needs an edges array — possibly empty — to compute edge routes. Thrown at layout.ts:73. Unlike nodes, this check doesn't accept missing edges; they must be an array.
Source
Thrown at packages/mermaid/src/rendering-util/layout-algorithms/cose-bilkent/layout.ts:73
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 (!data.rootNode) {
throw new Error('Root node is required');
}
if (!data.nodes || !Array.isArray(data.nodes)) {
throw new Error('No nodes found 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
- Always set data.edges to an array (use [] when there are no edges).
- Confirm the diagram-db layer emits edges as an array key named `edges`.
- If your data model uses a different key, map it to edges before layout.
- Add Array.isArray(data.edges) validation upstream to fail with a clearer message.
Example fix
// before
{ config, rootNode, nodes, layoutAlgorithm: 'cose-bilkent' } // edges missing
// after
{ config, rootNode, nodes, edges: [], layoutAlgorithm: 'cose-bilkent' } Defensive patterns
Strategy: validation
Validate before calling
if (!Array.isArray(data?.edges)) throw new Error('LayoutData.edges must be an array'); Type guard
function hasEdgesArray(d: any): d is { edges: unknown[] } { return Array.isArray(d?.edges); } Try / catch
try { validateLayoutData(data); } catch (e) { if (/Edges array is required/.test(String(e))) { data.edges = []; validateLayoutData(data); } else throw e; } Prevention
- Always set edges to [] when there are none — never omit or null it.
- Ensure the transform uses the `edges` key name.
- Validate with Array.isArray upstream.
When it happens
Trigger: A LayoutData with edges omitted entirely, or edges set to an object/Map/null. e.g. { config, rootNode, nodes, layoutAlgorithm } with no edges key. Array.isArray(null) is false, so explicitly-null edges also fail.
Common situations: A node-only diagram built manually without an edges field, a transform that stores edges under a different key (e.g. `connections`), or a fixture missing edges. Because the check requires an array, even 'no edges' must be expressed as [].
Related errors
- Root node is required
- No nodes found in layout data
- Layout data is required
- Configuration is required in layout data
- No nodes found in layout data
AI-assisted analysis of mermaid-js/mermaid@d93e9c88c0 (2026-08-12).
Data as JSON: /api/errors/1e48116b4d827c9d.
Report an issue: GitHub.