mermaid-js/mermaid · error
The service id [${id}] is already in use by another ${this.r
Error message
The service id [${id}] is already in use by another ${this.registeredIds.get(id)} What it means
Thrown by ArchitectureDB.addService when the service id already exists in registeredIds. The map stores every node/group id shared across services, junctions, and groups, so a collision with any prior entity (service, junction, or group) trips this. The suffix in the message ('node' or 'group') tells you which kind of entity already owns the id.
Source
Thrown at packages/mermaid/src/diagrams/architecture/architectureDb.ts:83
this.groups = new Map();
this.edges = [];
this.layoutHints = [];
this.registeredIds = new Map();
this.dataStructures = undefined;
this.elements = new Map();
this.diagramId = '';
commonClear();
}
public addService({
id,
icon,
in: parent,
title,
iconText,
}: Omit<ArchitectureService, 'edges'>): void {
if (this.registeredIds.has(id)) {
throw new Error(
`The service id [${id}] is already in use by another ${this.registeredIds.get(id)}`
);
}
if (parent !== undefined) {
if (id === parent) {
throw new Error(`The service [${id}] cannot be placed within itself`);
}
if (!this.registeredIds.has(parent)) {
throw new Error(
`The service [${id}]'s parent does not exist. Please make sure the parent is created before this service`
);
}
if (this.registeredIds.get(parent) === 'node') {
throw new Error(`The service [${id}]'s parent is not a group`);
}
}
this.registeredIds.set(id, 'node');View on GitHub (pinned to d93e9c88c0)
Solutions
- Give each service a unique id; namespace ids if labels repeat.
- Check db.getNode(id) / registeredIds before adding.
- If the duplicate is intentional, alias via a different id and a title.
Example fix
// before
db.addService({ id: 'api', icon: 'foo' });
db.addService({ id: 'api', icon: 'bar' }); // throws
// after
db.addService({ id: 'api', icon: 'foo' });
db.addService({ id: 'api2', title: 'api', icon: 'bar' }); Defensive patterns
Strategy: validation
Validate before calling
function assertUnique(db: ArchitectureDB, id: string) {
if (db.getNode(id)) throw new Error(`id '${id}' already exists`);
}
assertUnique(db, 'api');
db.addService({ id: 'api', icon: 'foo' }); Type guard
function isIdFree(db: ArchitectureDB, id: string): boolean {
return db.getNode(id) === null;
} Prevention
- Namespace ids (e.g. 'svc_', 'j_', 'grp_') to avoid cross-type collisions.
- Generate ids deterministically and dedupe before insertion.
- Check db.getNode(id) before every add* call.
When it happens
Trigger: Defining two services with the same id; reusing a junction or group id as a service id; calling addService twice in a loop without unique ids.
Common situations: Generator producing duplicate ids, copy-pasted architecture blocks, or parsing user text where the same label maps to the same id twice.
Related errors
- The junction id [${id}] is already in use by another ${this.
- The group id [${id}] is already in use by another ${this.reg
- The service [${id}] cannot be placed within itself
- The service [${id}]'s parent does not exist. Please make sur
- The service [${id}]'s parent is not a group
AI-assisted analysis of mermaid-js/mermaid@d93e9c88c0 (2026-08-12).
Data as JSON: /api/errors/d2f527cd24d5faec.
Report an issue: GitHub.