mermaid-js/mermaid · error

The junction id [${id}] is already in use by another ${this.

Error message

The junction id [${id}] is already in use by another ${this.registeredIds.get(id)}

What it means

Thrown by addJunction when the junction id already exists in registeredIds. Junctions share the same id namespace as services and groups, so the suffix ('node' or 'group') in the message identifies the prior owner. Junctions themselves are stored as 'node', so a junction can also collide with a service.

Source

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

    this.nodes.set(id, {
      id,
      type: 'service',
      icon,
      iconText,
      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');

View on GitHub (pinned to d93e9c88c0)

Solutions

  1. Use a distinct id namespace for junctions (e.g. prefix 'j_').
  2. Check registeredIds/getNode before adding.
  3. Rename the colliding entity if both must exist.

Example fix

// before
db.addJunction({ id: 'j1' });
db.addJunction({ id: 'j1' }); // throws

// after
db.addJunction({ id: 'j1' });
db.addJunction({ id: 'j2' });
Defensive patterns

Strategy: validation

Validate before calling

if (db.getNode(id) !== null) {
  throw new Error(`id '${id}' already in use`);
}
db.addJunction({ id });

Type guard

function isJunctionIdFree(db: ArchitectureDB, id: string): boolean {
  return db.getNode(id) === null;
}

Prevention

When it happens

Trigger: addJunction with an id already used by another junction, service, or group; adding a junction after a service with the same id.

Common situations: Auto-numbered junctions collide with service ids, or user text reuses a label for both a junction and a node.

Related errors


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