{"record":{"id":"0603a64daafcb3f4","repo":"mermaid-js/mermaid","slug":"no-diagram-type-detected-matching-given-configurat","errorCode":null,"errorMessage":"No diagram type detected matching given configuration for text: ${text}","messagePattern":"No diagram type detected matching given configuration for text: (.+?)","errorType":"validation","errorClass":"UnknownDiagramError","httpStatus":null,"severity":"error","filePath":"packages/mermaid/src/diagram-api/detectType.ts","lineNumber":48,"sourceCode":" *    g-->h\n * ```\n *\n * @param config - The mermaid config.\n * @returns A graph definition key\n */\nexport const detectType = function (text: string, config?: MermaidConfig): string {\n  text = text\n    .replace(frontMatterRegex, '')\n    .replace(directiveRegex, '')\n    .replace(anyCommentRegex, '\\n');\n  for (const [key, { detector }] of Object.entries(detectors)) {\n    const diagram = detector(text, config);\n    if (diagram) {\n      return key;\n    }\n  }\n\n  throw new UnknownDiagramError(\n    `No diagram type detected matching given configuration for text: ${text}`\n  );\n};\n\n/**\n * Registers lazy-loaded diagrams to Mermaid.\n *\n * The diagram function is loaded asynchronously, so that diagrams are only loaded\n * if the diagram is detected.\n *\n * @remarks\n * Please note that the order of diagram detectors is important.\n * The first detector to return `true` is the diagram that will be loaded\n * and used, so put more specific detectors at the beginning!\n *\n * @param diagrams - Diagrams to lazy load, and their detectors, in order of importance.\n */\nexport const registerLazyLoadedDiagrams = (...diagrams: ExternalDiagramDefinition[]) => {","sourceCodeStart":30,"sourceCodeEnd":66,"githubUrl":"https://github.com/mermaid-js/mermaid/blob/d93e9c88c01a599c062ee6a3f1462e3558ac6b90/packages/mermaid/src/diagram-api/detectType.ts#L30-L66","documentation":"Thrown by detectType when no registered detector returns truthy for the input text. Before testing detectors, the text is stripped of YAML front matter, %%{directive}%% blocks, and comments, so the remaining body must still match some diagram's detector (e.g. 'graph', 'sequenceDiagram'). It is an UnknownDiagramError.","triggerScenarios":"Passing plain prose or unrelated text, an empty string after stripping, a diagram keyword misspelled (e.g. 'garph TD'), or a syntax whose detector is not registered in this build.","commonSituations":"User submits free-form text to a mermaid renderer, a typo in the diagram declaration, or a stripped/slim build missing the relevant detector.","solutions":["Verify the text starts with a valid diagram keyword: 'graph', 'flowchart', 'sequenceDiagram', 'classDiagram', etc.","Trim and confirm the text is non-empty after removing comments/directives.","Ensure the relevant diagram module (and its detector) is registered in the build.","Wrap the parse call in try/catch and report an 'unrecognised diagram' error to the user."],"exampleFix":"// before\nconst type = detectType(userText, config);\n\n// after\nconst cleaned = userText.trim();\nif (!/^graph|^flowchart|^sequenceDiagram|^classDiagram/.test(cleaned)) {\n  throw new Error('Unrecognised diagram text');\n}\nconst type = detectType(cleaned, config);","handlingStrategy":"try-catch","validationCode":"const known = /^\\s*(graph|flowchart|sequenceDiagram|classDiagram|stateDiagram|erDiagram|gantt|pie|mindmap|architecture)\\b/i;\nif (!known.test(text)) {\n  throw new Error('Text does not start with a recognised diagram keyword');\n}","typeGuard":"function looksLikeDiagram(text: string): boolean {\n  return text.trim().length > 0 && known.some((kw) => text.trim().startsWith(kw));\n}","tryCatchPattern":"try {\n  const type = detectType(text, config);\n} catch (e) {\n  if (e instanceof UnknownDiagramError) {\n    // tell user the diagram syntax was not recognised\n  } else throw e;\n}","preventionTips":["Pre-validate that text begins with a known diagram keyword.","Strip stray leading characters/whitespace before detection.","Ensure all required detectors are registered in the build."],"tags":["mermaid","detection","diagram","unknown-diagram"],"backgroundTag":null,"analyzedSha":"d93e9c88c01a599c062ee6a3f1462e3558ac6b90","analyzedAt":"2026-08-12T06:23:11.304Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}