mermaid-js/mermaid · error · Error
Line definition not found
Error message
Line definition not found
What it means
Thrown at the end of drawArrow when the local variable lineDef is still undefined after every geometry branch was evaluated. lineDef is only assigned inside nested if/else blocks keyed on direction (TB/BT/LR), arrow rerouting, and coordinate relationships (p1.x vs p2.x, p1.y vs p2.y). If none of those conditions match — most notably when a commit position coordinate is NaN, making every comparison evaluate false — lineDef is never assigned and the safety check fires.
Source
Thrown at packages/mermaid/src/diagrams/git/gitGraphRenderer.ts:840
if (p1.y > p2.y) {
if (commitB.type === commitType.MERGE && commitA.id !== commitB.parents[0]) {
lineDef = `M ${p1.x} ${p1.y} L ${p2.x - radius} ${p1.y} ${arc} ${p2.x} ${
p1.y - offset
} L ${p2.x} ${p2.y}`;
} else {
lineDef = `M ${p1.x} ${p1.y} L ${p1.x} ${p2.y + radius} ${arc2} ${p1.x + offset} ${
p2.y
} L ${p2.x} ${p2.y}`;
}
}
if (p1.y === p2.y) {
lineDef = `M ${p1.x} ${p1.y} L ${p2.x} ${p2.y}`;
}
}
}
if (lineDef === undefined) {
throw new Error('Line definition not found');
}
svg
.append('path')
.attr('d', lineDef)
.attr(
'class',
'arrow arrow' + calcColorIndex(colorClassNum!, THEME_COLOR_LIMIT, useColorTheme)
);
};
const drawArrows = (
svg: d3.Selection<d3.BaseType, unknown, HTMLElement, any>,
commits: Map<string, Commit>
) => {
const gArrows = svg.append('g').attr('class', 'commit-arrows');
[...commits.keys()].forEach((key) => {
const commit = commits.get(key);
View on GitHub (pinned to d93e9c88c0)
Solutions
- Treat this as a symptom: inspect the commit positions passed to drawArrow and look for NaN/undefined coordinates, then fix the upstream layout that produced them.
- Temporarily switch the gitGraph direction to LR (default) to see if the throw disappears, isolating it to TB/BT geometry code.
- Reduce the diagram to the smallest case that reproduces and report it upstream with the diagram text and mermaid version.
- Upgrade to the latest mermaid patch release — geometry edge cases are fixed frequently.
Defensive patterns
Strategy: try-catch
Type guard
function positionsAreFinite(commitPos: Map<string, {x:number;y:number}>): boolean {
for (const p of commitPos.values()) {
if (!Number.isFinite(p.x) || !Number.isFinite(p.y)) return false;
}
return true;
} Try / catch
try {
await mermaid.render('g', diagramText);
} catch (e) {
if (e instanceof Error && /Line definition not found/.test(e.message)) {
// This is a downstream symptom of bad positions; ask user to simplify the graph
showUserError('Unable to compute arrow geometry. Try simplifying the gitGraph or switching direction.');
} else {
throw e;
}
} Prevention
- Treat this error as a symptom of upstream layout corruption (NaN positions) and investigate error 60 first.
- Keep gitGraph diagrams reasonably small to avoid geometry edge cases.
- Pin a known-good mermaid version and test diagrams when upgrading.
When it happens
Trigger: A commit position stored in commitPos has x or y equal to NaN, so comparisons like p1.y < p2.y, p1.y > p2.y, and p1.y === p2.y are all false and no branch runs; or an unexpected dir value outside TB/BT/LR; or a rerouting path whose sub-conditions all miss.
Common situations: Usually a downstream symptom of error 60 or of a layout computation producing NaN (e.g. division by zero in getCommitPosition); appears after changing theme/layout config that alters commit spacing math; rare in stable releases.
Related errors
- Position not found for branch ${branch.name}
- Commit positions not found for commits ${commitA.id} and ${c
- Groups within groups are not allowed in Kanban diagrams
- start should have been set during first phase
- end should have been set during first phase
AI-assisted analysis of mermaid-js/mermaid@d93e9c88c0 (2026-08-12).
Data as JSON: /api/errors/19af0a408659ccc0.
Report an issue: GitHub.