mermaid-js/mermaid · error

The left-hand id [${lhsId}] does not yet exist. Please creat

Error message

The left-hand id [${lhsId}] does not yet exist. Please create the service/group before declaring an edge to it.

What it means

Thrown by ArchitectureDB.addEdge when lhsId is present in neither the nodes map (services/junctions) nor the groups map. Both endpoints of an edge must be declared before the edge is added. The LHS check runs first, so this is the endpoint error you hit when the left-hand side is the missing one.

Source

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

    lhsInto,
    rhsInto,
    lhsGroup,
    rhsGroup,
    title,
  }: ArchitectureEdge): void {
    if (!isArchitectureDirection(lhsDir)) {
      throw new Error(
        `Invalid direction given for left hand side of edge ${lhsId}--${rhsId}. Expected (L,R,T,B) got ${String(lhsDir)}`
      );
    }
    if (!isArchitectureDirection(rhsDir)) {
      throw new Error(
        `Invalid direction given for right hand side of edge ${lhsId}--${rhsId}. Expected (L,R,T,B) got ${String(rhsDir)}`
      );
    }

    if (!this.nodes.has(lhsId) && !this.groups.has(lhsId)) {
      throw new Error(
        `The left-hand id [${lhsId}] does not yet exist. Please create the service/group before declaring an edge to it.`
      );
    }
    if (!this.nodes.has(rhsId) && !this.groups.has(rhsId)) {
      throw new Error(
        `The right-hand id [${rhsId}] does not yet exist. Please create the service/group before declaring an edge to it.`
      );
    }

    const lhsGroupId = this.nodes.get(lhsId)!.in;
    const rhsGroupId = this.nodes.get(rhsId)!.in;
    if (lhsGroup && lhsGroupId && rhsGroupId && lhsGroupId == rhsGroupId) {
      throw new Error(
        `The left-hand id [${lhsId}] is modified to traverse the group boundary, but the edge does not pass through two groups.`
      );
    }
    if (rhsGroup && lhsGroupId && rhsGroupId && lhsGroupId == rhsGroupId) {
      throw new Error(

View on GitHub (pinned to d93e9c88c0)

Solutions

  1. Declare the left-hand service, junction, or group before calling addEdge.
  2. Check the spelling and case of lhsId against the declaration.

Example fix

// before
db.addEdge({ lhsId: 'api', rhsId: 'db', lhsDir: 'L', rhsDir: 'R' }); // 'api' not declared
// after
db.addService({ id: 'api' });
db.addService({ id: 'db' });
db.addEdge({ lhsId: 'api', rhsId: 'db', lhsDir: 'L', rhsDir: 'R' });
Defensive patterns

Strategy: validation

Validate before calling

function addEdgeSafe(db, e) {
  const exists = (id) => db.getNode(id) !== null || db.getGroups().some(g => g.id === id);
  if (!exists(e.lhsId)) {
    throw new Error(`lhsId '${e.lhsId}' is not declared`);
  }
  db.addEdge(e);
}

Prevention

When it happens

Trigger: Calling db.addEdge({ lhsId: 'ghost', rhsId: 'a', lhsDir: 'L', rhsDir: 'R' }) where 'ghost' was never registered via addService/addJunction/addGroup.

Common situations: Declaring an edge before the service/group it connects; typo in the lhs id; referencing an id declared in a different/cleared DB instance.

Related errors


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