mermaid-js/mermaid · error
An align directive requires at least two members; got ${hint
Error message
An align directive requires at least two members; got ${hint.members.length} What it means
Thrown by ArchitectureDB.addLayoutHint when hint.members has fewer than 2 entries. An align directive aligns two or more nodes along a row or column, so a single-member or empty alignment is meaningless. Note the Langium grammar already requires `(members+=ID)+`, so this guard primarily protects non-grammar (programmatic) callers.
Source
Thrown at packages/mermaid/src/diagrams/architecture/architectureDb.ts:265
title,
};
this.edges.push(edge);
const lhsNode = this.nodes.get(lhsId);
const rhsNode = this.nodes.get(rhsId);
if (lhsNode && rhsNode) {
lhsNode.edges.push(this.edges[this.edges.length - 1]);
rhsNode.edges.push(this.edges[this.edges.length - 1]);
}
}
public getEdges(): ArchitectureEdge[] {
return this.edges;
}
public addLayoutHint(hint: ArchitectureLayoutHint): void {
if (hint.members.length < 2) {
throw new Error(
`An align directive requires at least two members; got ${hint.members.length}`
);
}
const seen = new Set<string>();
hint.members.forEach((id) => {
if (this.registeredIds.get(id) !== 'node') {
throw new Error(
`align ${hint.direction} references [${id}], which is not a service or junction`
);
}
if (seen.has(id)) {
throw new Error(`align ${hint.direction} lists [${id}] more than once`);
}
seen.add(id);
});
this.layoutHints.push(hint);
}
View on GitHub (pinned to d93e9c88c0)
Solutions
- Ensure members contains at least 2 ids.
- Skip emitting the hint entirely when fewer than 2 members would be present.
Example fix
// before
db.addLayoutHint({ direction: 'row', members: ['a'] });
// after
db.addLayoutHint({ direction: 'row', members: ['a', 'b'] }); Defensive patterns
Strategy: validation
Validate before calling
function addLayoutHintSafe(db, hint) {
if (hint.members.length < 2) {
throw new Error(`align needs >=2 members; got ${hint.members.length}`);
}
db.addLayoutHint(hint);
} Prevention
- Skip emitting align hints with fewer than 2 members.
- When generating from data, filter out degenerate single-member alignments.
When it happens
Trigger: Calling db.addLayoutHint({ direction: 'row', members: [] }) or members: ['only_one']. In DSL this is hard to hit because the grammar enforces >=1, but a single-member align can still slip through some code paths.
Common situations: Programmatic generation of layout hints that produces empty or singleton arrays; DSL edge cases where a rule reduces members to one; tests exercising the DB API directly.
Related errors
- align ${hint.direction} references [${id}], which is not a s
- align ${hint.direction} lists [${id}] more than once
- No nodes found in layout data
- Layout data is required
- Configuration is required in layout data
AI-assisted analysis of mermaid-js/mermaid@d93e9c88c0 (2026-08-12).
Data as JSON: /api/errors/55f42f91d9b38ff3.
Report an issue: GitHub.