mermaid-js/mermaid · error

unknown set identifier: ${unknown.join(', ')}

Error message

unknown set identifier: ${unknown.join(', ')}

What it means

Venn sets are first registered as singletons: addSubsetData with one identifier adds that id to knownSets. validateUnionIdentifiers() then checks that every identifier referenced by a union/intersection set was previously declared as a singleton; any id not in knownSets is reported back as unknown.

Source

Thrown at packages/mermaid/src/diagrams/venn/vennDB.ts:84

  for (const [key, value] of data) {
    styles[key] = normalizeStyleValue(value) ?? value;
  }
  styleEntries.push({ targets, styles });
};

export const getStyleData = () => {
  return styleEntries;
};

const normalizeIdentifierList = (identifierList: string[]) => {
  return identifierList.map((identifier) => normalizeText(identifier));
};

export const validateUnionIdentifiers: VennDB['validateUnionIdentifiers'] = (identifierList) => {
  const normalized = normalizeIdentifierList(identifierList);
  const unknown = normalized.filter((identifier) => !knownSets.has(identifier));
  if (unknown.length > 0) {
    throw new Error(`unknown set identifier: ${unknown.join(', ')}`);
  }
};

export const getTextData = () => {
  return textNodes;
};

export const getCurrentSets: VennDB['getCurrentSets'] = () => currentSets;
export const getIndentMode: VennDB['getIndentMode'] = () => indentMode;
export const setIndentMode: VennDB['setIndentMode'] = (enabled) => {
  indentMode = enabled;
};

const DEFAULT_VENN_CONFIG: Required<VennDiagramConfig> = DEFAULT_CONFIG.venn;

function getConfig(): Required<VennDiagramConfig> {
  return cleanAndMerge(DEFAULT_VENN_CONFIG, commonGetConfig().venn);
}

View on GitHub (pinned to d93e9c88c0)

Solutions

  1. Declare each referenced set as a singleton (one identifier) before using it in a union/intersection.
  2. Match identifier spelling exactly, including the same quoting, between singleton and union.
  3. Remove unions that reference sets you no longer declare.
  4. Define singletons first, then unions, to guarantee registration order.

Example fix

// before — B referenced but never declared alone
A: 10
A|B: 5

// after
A: 10
B: 8
A|B: 5
Defensive patterns

Strategy: validation

Validate before calling

// Collect declared singleton sets, then verify unions reference only those
const known = new Set<string>();
singletons.forEach(s => known.add(normalize(s)));
for (const u of unions) {
  for (const id of u.ids) {
    if (!known.has(normalize(id))) throw new Error(`unknown set identifier: ${id}`);
  }
}
// normalize = trim and strip surrounding quotes

Type guard

const isUnknownSetError = (e): boolean =>
  e instanceof Error && /^unknown set identifier:/.test(e.message);

Try / catch

try {
  vennDB.validateUnionIdentifiers(ids);
} catch (e) {
  if (e instanceof Error && /^unknown set identifier:/.test(e.message)) {
    // extract the listed ids and ensure each is declared as a singleton
  } else { throw e; }
}

Prevention

When it happens

Trigger: Defining an intersection/union set (two or more identifiers) that references an identifier never declared on its own, e.g. `A & B` where `B` was never a standalone `A` set. Case/quote differences also count as unknown because identifiers are normalised (trimmed, quotes stripped) before comparison.

Common situations: Typing a set name differently between its singleton declaration and the union; reordering so the union appears before the singleton; deleting a singleton but leaving a union that uses it; quoting inconsistently (`"A"` vs `A`).

Related errors


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