mermaid-js/mermaid · error

Configuration is required in layout data

Error message

Configuration is required in layout data

What it means

Thrown by validateLayoutData when data is truthy but data.config is falsy. The tidy-tree layout expects a Mermaid configuration block inside LayoutData, and its absence indicates the object was constructed incompletely (e.g. copied from a graph that never carried config).

Source

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

      sourceHeight: sourceNode?.height,
      targetWidth: targetNode?.width,
      targetHeight: targetNode?.height,
    };
  });
}

/**
 * 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

  1. Always attach a config object (typically mermaidApi.getConfig() or the originating diagram's config).
  2. Spread the source LayoutData so config propagates: {...partial, config: getConfig()}.
  3. Default to an empty config object {} if the layout genuinely needs no options.

Example fix

// before
validateLayoutData({ nodes, edges });

// after
validateLayoutData({ nodes, edges, config: getConfig() });
Defensive patterns

Strategy: validation

Validate before calling

const safe = { ...data, config: data?.config ?? getConfig() };
validateLayoutData(safe);

Type guard

function hasConfig(data: unknown): data is { config: object } {
  return !!data && typeof (data as any).config === 'object' && (data as any).config !== null;
}

Prevention

When it happens

Trigger: Calling validateLayoutData({nodes:[...], edges:[...]}) with no config field; passing a partial LayoutData built from node/edge arrays only.

Common situations: LayoutData assembled manually from extracted nodes/edges without forwarding the original diagram config, or a config-stripping step upstream removed the field.

Related errors


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