mermaid-js/mermaid · error

The group [${id}]'s parent does not exist. Please make sure

Error message

The group [${id}]'s parent does not exist. Please make sure the parent is created before this group

What it means

Thrown by ArchitectureDB.addGroup when the `in` (parent) field references an id that is not present in registeredIds. Groups must be declared top-down: the parent must exist before any child group references it. The DB keeps a single registeredIds map of every node and group, and a miss here means the parent was never created.

Source

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

    return [...this.nodes.values()];
  }

  public getNode(id: string): ArchitectureNode | null {
    return this.nodes.get(id) ?? null;
  }

  public addGroup({ id, icon, in: parent, title }: ArchitectureGroup): void {
    if (this.registeredIds.has(id)) {
      throw new Error(
        `The group id [${id}] is already in use by another ${this.registeredIds.get(id)}`
      );
    }
    if (parent !== undefined) {
      if (id === parent) {
        throw new Error(`The group [${id}] cannot be placed within itself`);
      }
      if (!this.registeredIds.has(parent)) {
        throw new Error(
          `The group [${id}]'s parent does not exist. Please make sure the parent is created before this group`
        );
      }
      if (this.registeredIds.get(parent) === 'node') {
        throw new Error(`The group [${id}]'s parent is not a group`);
      }
    }

    this.registeredIds.set(id, 'group');

    this.groups.set(id, {
      id,
      icon,
      title,
      in: parent,
    });
  }
  public getGroups(): ArchitectureGroup[] {

View on GitHub (pinned to d93e9c88c0)

Solutions

  1. Declare the parent group (via addGroup) before declaring the child.
  2. Drop the `in` field if the group is intended to be top-level.
  3. Check for a typo in the parent id — it must match an existing registered id exactly.

Example fix

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

Strategy: validation

Validate before calling

function addGroupSafe(db, g) {
  if (g.in !== undefined && !db.getGroups().some(gr => gr.id === g.in)
      && !db.getNodes().some(n => n.id === g.in)) {
    throw new Error(`Parent '${g.in}' is not registered`);
  }
  db.addGroup(g);
}

Prevention

When it happens

Trigger: Calling db.addGroup({ id: 'child', in: 'parent' }) when 'parent' has not been added via addGroup/addService/addJunction yet. In DSL: declaring `group child in parent` before `group parent`.

Common situations: Ordering mistakes in hand-written DSL where a child group appears before its parent; programmatic API calls issued in the wrong sequence; renaming a parent without updating children.

Related errors


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