mermaid-js/mermaid · error · Error
Unknown diagram type: ${diagramType}
Error message
Unknown diagram type: ${diagramType} What it means
Thrown by parse() when diagramType is not a key of the `initializers` map (the registry of lazy diagram-parser factories). Each key (info, packet, pie, treeView, architecture, gitGraph, eventmodeling, radar, railroad, railroadEbnf, railroadAbnf, railroadPeg, treemap, wardley, cynefin) has an async initializer that loads its Langium parser on demand. An unrecognized type short-circuits before any parsing.
Source
Thrown at packages/parser/src/parse.ts:139
export async function parse(diagramType: 'architecture', text: string): Promise<Architecture>;
export async function parse(diagramType: 'gitGraph', text: string): Promise<GitGraph>;
export async function parse(diagramType: 'eventmodeling', text: string): Promise<EventModel>;
export async function parse(diagramType: 'radar', text: string): Promise<Radar>;
export async function parse(diagramType: 'railroad', text: string): Promise<Railroad>;
export async function parse(diagramType: 'railroadEbnf', text: string): Promise<RailroadEbnf>;
export async function parse(diagramType: 'railroadAbnf', text: string): Promise<RailroadAbnf>;
export async function parse(diagramType: 'railroadPeg', text: string): Promise<RailroadPeg>;
export async function parse(diagramType: 'treemap', text: string): Promise<Treemap>;
export async function parse(diagramType: 'wardley', text: string): Promise<Wardley>;
export async function parse(diagramType: 'cynefin', text: string): Promise<Cynefin>;
export async function parse<T extends DiagramAST>(
diagramType: keyof typeof initializers,
text: string
): Promise<T> {
const initializer = initializers[diagramType];
if (!initializer) {
throw new Error(`Unknown diagram type: ${diagramType}`);
}
if (!parsers[diagramType]) {
await initializer();
}
const parser: LangiumParser = parsers[diagramType];
const result: ParseResult<T> = parser.parse<T>(text);
if (result.lexerErrors.length > 0 || result.parserErrors.length > 0) {
throw new MermaidParseError(result);
}
return result.value;
}
export class MermaidParseError extends Error {
constructor(public result: ParseResult<DiagramAST>) {
const lexerErrors: string = result.lexerErrors
.map((err) => {
const line = err.line !== undefined && !isNaN(err.line) ? err.line : '?';
const column = err.column !== undefined && !isNaN(err.column) ? err.column : '?';View on GitHub (pinned to d93e9c88c0)
Solutions
- Pass one of the supported keys: info, packet, pie, treeView, architecture, gitGraph, eventmodeling, radar, railroad, railroadEbnf, railroadAbnf, railroadPeg, treemap, wardley, cynefin (exact case).
- For flowchart/sequence/state/class/etc., use mermaid's main API rather than this low-level parse().
- Validate diagramType against Object.keys(initializers) before calling parse.
- Normalize user input (lowercase, camelCase) before lookup.
Example fix
// before
await parse('tree-view', text); // wrong key, throws
// after
await parse('treeView', text); // correct key Defensive patterns
Strategy: validation
Validate before calling
const KNOWN_TYPES = ['info','packet','pie','treeView','architecture','gitGraph','eventmodeling','radar','railroad','railroadEbnf','railroadAbnf','railroadPeg','treemap','wardley','cynefin'] as const;
function isKnownDiagramType(t: string): boolean { return (KNOWN_TYPES as readonly string[]).includes(t); }
if (!isKnownDiagramType(type)) throw new Error(`unsupported diagram type: ${type}`); Type guard
function isDiagramType(t: unknown, known: readonly string[]): t is string { return typeof t === 'string' && known.includes(t); } Try / catch
try { return await parse(type, text); } catch (e) { if (/Unknown diagram type/.test(String(e))) { throw new Error(`'${type}' is not a Langium-parsed diagram; use mermaid's main API`); } throw e; } Prevention
- Use the exact initializer keys (camelCase where applicable, e.g. 'treeView').
- For flowchart/sequence/state, use mermaid's higher-level API, not this parse().
- Normalize and validate user-supplied diagram types before lookup.
When it happens
Trigger: Calling parse('flowchart', text) (flowchart isn't in this parser registry — it has its own), parse('sequence', text), or a typo like parse('Pie', text) (case-sensitive), parse('tree-view', text) (the key is 'treeView'), or parse('', text). Any diagramType not in the initializers keys throws.
Common situations: Mixing up the @mermaid-parser parse registry with mermaid's higher-level diagram registry (some diagrams like flowchart/sequence/state aren't Langium-parsed here), case or naming mismatches (kebab-case vs camelCase), or passing a user-supplied diagram type without validating.
Related errors
- No nodes found in layout data
- Layout data is required
- Configuration is required in layout data
- Nodes array is required in layout data
- Edges array is required in layout data
AI-assisted analysis of mermaid-js/mermaid@d93e9c88c0 (2026-08-12).
Data as JSON: /api/errors/4cbbd98d1b13d06b.
Report an issue: GitHub.