{"record":{"id":"86df9a6deff7724d","repo":"mermaid-js/mermaid","slug":"diagram-type-not-found","errorCode":null,"errorMessage":"Diagram ${type} not found.","messagePattern":"Diagram (.+?) not found\\.","errorType":"exception","errorClass":"UnknownDiagramError","httpStatus":null,"severity":"error","filePath":"packages/mermaid/src/Diagram.ts","lineNumber":26,"sourceCode":"\n// eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents\nexport type ParseErrorFunction = (err: string | DetailedError | unknown, hash?: any) => void;\n\n/**\n * An object representing a parsed mermaid diagram definition.\n * @privateRemarks This is exported as part of the public mermaidAPI.\n */\nexport class Diagram {\n  public static async fromText(text: string, metadata: Pick<DiagramMetadata, 'title'> = {}) {\n    const config = configApi.getConfig();\n    const type = detectType(text, config);\n    text = encodeEntities(text) + '\\n';\n    try {\n      getDiagram(type);\n    } catch {\n      const loader = getDiagramLoader(type);\n      if (!loader) {\n        throw new UnknownDiagramError(`Diagram ${type} not found.`);\n      }\n      // Diagram not available, loading it.\n      // new diagram will try getDiagram again and if fails then it is a valid throw\n      const { id, diagram } = await loader();\n      registerDiagram(id, diagram);\n    }\n    const { db, parser, renderer, init } = getDiagram(type);\n    if (parser.parser) {\n      // The parser.parser.yy is only present in JISON parsers. So, we'll only set if required.\n      parser.parser.yy = db;\n    }\n    db.clear?.();\n    init?.(config);\n    // This block was added for legacy compatibility. Use frontmatter instead of adding more special cases.\n    if (metadata.title) {\n      db.setDiagramTitle?.(metadata.title);\n    }\n    await parser.parse(text);","sourceCodeStart":8,"sourceCodeEnd":44,"githubUrl":"https://github.com/mermaid-js/mermaid/blob/d93e9c88c01a599c062ee6a3f1462e3558ac6b90/packages/mermaid/src/Diagram.ts#L8-L44","documentation":"Thrown by Diagram.fromText after detectType returns a key but getDiagram cannot find it in the registry and getDiagramLoader returns no lazy loader for that type. It is an UnknownDiagramError, meaning the detector recognised the syntax but no implementation (built-in or lazy-loaded) is available to render it.","triggerScenarios":"Text matches a detector for a diagram type whose package was never registered (e.g. an external diagram not bundled in the build), or a custom detector returns an unregistered key.","commonSituations":"Using a slimmed-down mermaid build that omits a diagram module, a version mismatch where a detector exists but its loader was removed, or registering a detector without its corresponding diagram.","solutions":["Register the missing diagram: import and registerDiagram(...) or include the external diagram bundle.","Switch to the full mermaid build that ships all built-in diagrams.","Verify the detected type matches a registered id; if a custom detector returns an unknown key, register its implementation.","Catch UnknownDiagramError and surface a user-facing 'unsupported diagram' message."],"exampleFix":"// before\nconst d = await Diagram.fromText(text);\n\n// after\nimport { registerDiagram } from 'mermaid';\nawait registerMyDiagram(); // registers id + loader\nconst d = await Diagram.fromText(text);","handlingStrategy":"try-catch","validationCode":"import { detectType, getDiagramLoader } from 'mermaid';\n\nconst type = detectType(text, config);\nif (!getDiagramLoader(type)) {\n  throw new Error(`No loader registered for diagram type '${type}'`);\n}","typeGuard":"function hasLoader(type: string): boolean {\n  return !!getDiagramLoader(type);\n}","tryCatchPattern":"import { UnknownDiagramError } from 'mermaid';\ntry {\n  const d = await Diagram.fromText(text);\n} catch (e) {\n  if (e instanceof UnknownDiagramError) {\n    // surface 'unsupported diagram' to the user\n  } else throw e;\n}","preventionTips":["Bundle or register every diagram type your input may contain.","Validate detected type against registered loaders before parsing.","Run integration tests that exercise each supported diagram type."],"tags":["mermaid","diagram","registry","loader","unknown-diagram"],"backgroundTag":null,"analyzedSha":"d93e9c88c01a599c062ee6a3f1462e3558ac6b90","analyzedAt":"2026-08-12T06:23:11.304Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}