mermaid-js/mermaid · error · Error
Configuration is required in layout data
Error message
Configuration is required in layout data
What it means
Second guard in validateLayoutData: `data` itself is truthy but `data.config` is missing. The cose-bilkent layout needs the MermaidConfig to drive cytoscape options, so a LayoutData without its config block is rejected before cytoscape is created. Thrown at layout.ts:61.
Source
Thrown at packages/mermaid/src/rendering-util/layout-algorithms/cose-bilkent/layout.ts:61
};
} catch (error) {
log.error('Error in cose-bilkent layout algorithm:', error);
throw error;
}
}
/**
* 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 (!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
- Attach the active MermaidConfig to data.config before calling the layout (the standard render path does this automatically — use it instead of calling executeCoseBilkentLayout directly).
- If building LayoutData manually, spread the config in: { ...rest, config: mermaidConfig }.
- Add a unit-test fixture that includes a minimal valid config object.
- Log data.config at the call site to confirm it is populated.
Example fix
// before
{ rootNode, nodes, edges, layoutAlgorithm: 'cose-bilkent' }
// after
{ rootNode, nodes, edges, layoutAlgorithm: 'cose-bilkent', config: mermaidConfig } Defensive patterns
Strategy: validation
Validate before calling
if (!data?.config) throw new Error('LayoutData.config missing — attach the active MermaidConfig'); Type guard
function hasConfig(d: any): d is { config: object } { return d && typeof d.config === 'object' && d.config !== null; } Try / catch
try { validateLayoutData(data); } catch (e) { if (/Configuration is required/.test(String(e))) { data.config = mermaidConfig; validateLayoutData(data); } else throw e; } Prevention
- Use the standard render pipeline which attaches config automatically.
- When building LayoutData manually, always spread the mermaid config.
- Add a fixture/test that includes a valid config block.
When it happens
Trigger: A LayoutData object assembled without the config field, e.g. { rootNode, nodes, edges, layoutAlgorithm } with config omitted, or a partial spread that dropped config. Also if a transformer sets config to null explicitly.
Common situations: Custom diagram integrations that hand-build LayoutData and forget to attach the mermaid config; a refactor that moved config to a sibling property; or a mock/fixture used in tests missing the config block.
Related errors
- Layout data is required
- Root node is required
- No nodes found in layout data
- Edges array 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/0e9eb2270f0b93dc.
Report an issue: GitHub.