mermaid-js/mermaid · error
The service [${id}] cannot be placed within itself
Error message
The service [${id}] cannot be placed within itself What it means
Thrown by addService when the service's parent ('in' field) equals its own id. Placing a service inside itself would create a self-referential containment cycle, so the db rejects it explicitly before any structural work.
Source
Thrown at packages/mermaid/src/diagrams/architecture/architectureDb.ts:89
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');
this.nodes.set(id, {
id,
type: 'service',
icon,
iconText,View on GitHub (pinned to d93e9c88c0)
Solutions
- Ensure the parent id differs from the service id.
- Omit the 'in' field when the service is top-level.
- Validate id !== parent before calling addService.
Example fix
// before
db.addService({ id: 'svc', in: 'svc' });
// after
db.addService({ id: 'svc' }); // top-level
// or
db.addService({ id: 'svc', in: 'groupA' }); Defensive patterns
Strategy: validation
Validate before calling
if (id === parent) {
throw new Error(`Service '${id}' cannot be its own parent`);
}
db.addService({ id, in: parent }); Prevention
- Always derive parent from a separate source than the node id.
- Omit 'in' for top-level services.
When it happens
Trigger: addService({ id: 'X', in: 'X' }); or user text like 'service: X { ... } in X'.
Common situations: Auto-generated architecture specs where a node is mistakenly listed as its own parent, or a templating bug copies a node id into its parent slot.
Related errors
- The service [${id}]'s parent does not exist. Please make sur
- The service [${id}]'s parent is not a group
- The junction [${id}] cannot be placed within itself
- The junction [${id}]'s parent does not exist. Please make su
- The junction [${id}]'s parent is not a group
AI-assisted analysis of mermaid-js/mermaid@d93e9c88c0 (2026-08-12).
Data as JSON: /api/errors/4cc7f141a0125515.
Report an issue: GitHub.