mermaid-js/mermaid · error
The junction [${id}] cannot be placed within itself
Error message
The junction [${id}] cannot be placed within itself What it means
Thrown by addJunction when its parent ('in') equals its own id, mirroring the self-containment guard on services. A junction cannot be its own container, so the db rejects id === parent before registration.
Source
Thrown at packages/mermaid/src/diagrams/architecture/architectureDb.ts:126
title,
edges: [],
in: parent,
});
}
public getServices(): ArchitectureService[] {
return [...this.nodes.values()].filter(isArchitectureService);
}
public addJunction({ id, in: parent }: Omit<ArchitectureJunction, 'edges'>): void {
if (this.registeredIds.has(id)) {
throw new Error(
`The junction id [${id}] is already in use by another ${this.registeredIds.get(id)}`
);
}
if (parent !== undefined) {
if (id === parent) {
throw new Error(`The junction [${id}] cannot be placed within itself`);
}
if (!this.registeredIds.has(parent)) {
throw new Error(
`The junction [${id}]'s parent does not exist. Please make sure the parent is created before this junction`
);
}
if (this.registeredIds.get(parent) === 'node') {
throw new Error(`The junction [${id}]'s parent is not a group`);
}
}
this.registeredIds.set(id, 'node');
this.nodes.set(id, {
id,
type: 'junction',
edges: [],
in: parent,View on GitHub (pinned to d93e9c88c0)
Solutions
- Ensure parent id differs from the junction id.
- Drop the 'in' field for a top-level junction.
- Validate id !== parent before addJunction.
Example fix
// before
db.addJunction({ id: 'j', in: 'j' });
// after
db.addJunction({ id: 'j' }); Defensive patterns
Strategy: validation
Validate before calling
if (id === parent) {
throw new Error(`Junction '${id}' cannot be its own parent`);
}
db.addJunction({ id, in: parent }); Prevention
- Keep parent assignment independent of the junction id.
- Omit 'in' for top-level junctions.
When it happens
Trigger: addJunction({ id: 'X', in: 'X' }); or generated layout hint that lists a junction as its own parent.
Common situations: Programmatic spec builder assigns the same id to a junction and its parent slot, or a templating copy bug.
Related errors
- The service [${id}] cannot be placed within itself
- The junction id [${id}] is already in use by another ${this.
- The junction [${id}]'s parent does not exist. Please make su
- The junction [${id}]'s parent is not a group
- The service id [${id}] is already in use by another ${this.r
AI-assisted analysis of mermaid-js/mermaid@d93e9c88c0 (2026-08-12).
Data as JSON: /api/errors/74caa83ff7343e72.
Report an issue: GitHub.