mermaid-js/mermaid · error

The service [${id}]'s parent is not a group

Error message

The service [${id}]'s parent is not a group

What it means

Thrown by addService when the referenced parent exists in registeredIds but is tagged 'node' rather than 'group'. Only groups can contain services, so nesting a service under another service or a junction is rejected.

Source

Thrown at packages/mermaid/src/diagrams/architecture/architectureDb.ts:97

    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,
      title,
      edges: [],
      in: parent,
    });
  }

  public getServices(): ArchitectureService[] {
    return [...this.nodes.values()].filter(isArchitectureService);

View on GitHub (pinned to d93e9c88c0)

Solutions

  1. Make the container a group: addGroup first, then nest the service under it.
  2. If the intended parent is a service, flatten the hierarchy or wrap both in a group.

Example fix

// before
db.addService({ id: 'parent' });
db.addService({ id: 'child', in: 'parent' }); // throws: parent is a node

// after
db.addGroup({ id: 'parent' });
db.addService({ id: 'child', in: 'parent' });
Defensive patterns

Strategy: validation

Validate before calling

if (parent) {
  const p = db.getGroups().find((g) => g.id === parent);
  if (!p) throw new Error(`'${parent}' is not a group; cannot nest`);
}
db.addService({ id, in: parent });

Prevention

When it happens

Trigger: addService({ id: 'b', in: 'a' }) where 'a' was previously added via addService or addJunction (both register as 'node').

Common situations: User nests one service inside another service instead of inside a group, or mistakes a junction for a container.

Related errors


AI-assisted analysis of mermaid-js/mermaid@d93e9c88c0 (2026-08-12). Data as JSON: /api/errors/4c20615a7533b1a0. Report an issue: GitHub.