mermaid-js/mermaid · error

The created participant ${this.state.records.lastCreated.nam

Error message

The created participant ${this.state.records.lastCreated.name} does not have an associated creating message after its declaration. Please check the sequence diagram.

What it means

When `create Participant` is parsed, lastCreated is set; the very next message must be addressed `to` that participant (the creating message). If the next message's `to` differs, mermaid throws because the create would be orphaned — a created participant must be born by a message targeting it.

Source

Thrown at packages/mermaid/src/diagrams/sequence/sequenceDb.ts:625

        case 'addNote':
          this.addNote(param.actor, param.placement, param.text);
          break;
        case 'addLinks':
          this.addLinks(param.actor, param.text);
          break;
        case 'addALink':
          this.addALink(param.actor, param.text);
          break;
        case 'addProperties':
          this.addProperties(param.actor, param.text);
          break;
        case 'addDetails':
          this.addDetails(param.actor, param.text);
          break;
        case 'addMessage':
          if (this.state.records.lastCreated) {
            if (param.to !== this.state.records.lastCreated) {
              throw new Error(
                'The created participant ' +
                  this.state.records.lastCreated.name +
                  ' does not have an associated creating message after its declaration. Please check the sequence diagram.'
              );
            } else {
              this.state.records.lastCreated = undefined;
            }
          } else if (this.state.records.lastDestroyed) {
            if (
              param.to !== this.state.records.lastDestroyed &&
              param.from !== this.state.records.lastDestroyed
            ) {
              throw new Error(
                'The destroyed participant ' +
                  this.state.records.lastDestroyed.name +
                  ' does not have an associated destroying message after its declaration. Please check the sequence diagram.'
              );
            } else {

View on GitHub (pinned to d93e9c88c0)

Solutions

  1. Make the message immediately after `create X` target X (`A ->> create X`).
  2. Remove the `create` if you only need a normal participant (use `participant`).
  3. Ensure no blank statements break the create→message adjacency.
  4. Double-check the created id spelling matches the recipient exactly.

Example fix

// before
create Bob
Alice ->> Charlie : hi  // not addressed to Bob

// after
create Bob
Alice ->> Bob : hi
Defensive patterns

Strategy: validation

Validate before calling

// Structural check: a create must be immediately followed by a message to that actor
for (let i = 0; i < lines.length; i++) {
  if (/^\s*create\s+(\S+)/.test(lines[i])) {
    const id = RegExp.$1;
    const next = lines[i + 1];
    if (!next || !new RegExp(`->.*${id}|${id}.*->`).test(next)) {
      throw new Error(`create ${id} not followed by a message to ${id}`);
    }
  }
}

Type guard

const isCreateOrphanError = (e): boolean =>
  e instanceof Error && /created participant .* does not have an associated creating message/.test(e.message);

Try / catch

try {
  await mermaid.run({ nodes: [el] });
} catch (e) {
  if (e instanceof Error && /created participant .* does not have/.test(e.message)) {
    // ensure next line after `create X` is `A ->> X : ...`
  } else { throw e; }
}

Prevention

When it happens

Trigger: A `create` directive followed by a message whose recipient is not the created actor, or by a non-message statement, before any message `to` the created actor.

Common situations: Inserting a comment or another statement right after `create`; mistyping the target name; reordering messages so the create is no longer adjacent to its intro message; tooling that emits `create` and the message separately.

Related errors


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