{"record":{"id":"73b7ca8d94ef8af6","repo":"mermaid-js/mermaid","slug":"unknown-layout-algorithm-data4layout-layoutalgo","errorCode":null,"errorMessage":"Unknown layout algorithm: ${data4Layout.layoutAlgorithm}","messagePattern":"Unknown layout algorithm: (.+?)","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/mermaid/src/rendering-util/render.ts","lineNumber":64,"sourceCode":"      name: 'swimlane',\n      loader: async () => await import('./layout-algorithms/swimlanes/index.js'),\n    },\n    ...(injected.includeLargeFeatures\n      ? [\n          {\n            name: 'cose-bilkent',\n            loader: async () => await import('./layout-algorithms/cose-bilkent/index.js'),\n          },\n        ]\n      : []),\n  ]);\n};\n\nregisterDefaultLayoutLoaders();\n\nexport const render = async (data4Layout: LayoutData, svg: SVG) => {\n  if (!(data4Layout.layoutAlgorithm in layoutAlgorithms)) {\n    throw new Error(`Unknown layout algorithm: ${data4Layout.layoutAlgorithm}`);\n  }\n\n  // Prefix all node domIds with the diagram's SVG element ID to ensure uniqueness\n  // across multiple diagrams on the same page.\n  if (data4Layout.diagramId) {\n    for (const node of data4Layout.nodes) {\n      const originalDomId = node.domId || node.id;\n      node.domId = `${data4Layout.diagramId}-${originalDomId}`;\n    }\n  }\n\n  const layoutDefinition = layoutAlgorithms[data4Layout.layoutAlgorithm];\n  const layoutRenderer = await layoutDefinition.loader();\n\n  const { theme, themeVariables } = data4Layout.config;\n  const { useGradient, gradientStart, gradientStop } = themeVariables;\n\n  const svgId = svg.attr('id');","sourceCodeStart":46,"sourceCodeEnd":82,"githubUrl":"https://github.com/mermaid-js/mermaid/blob/d93e9c88c01a599c062ee6a3f1462e3558ac6b90/packages/mermaid/src/rendering-util/render.ts#L46-L82","documentation":"Thrown by render() when data4Layout.layoutAlgorithm is not a key in the layoutAlgorithms registry. The registry is populated by registerLayoutLoaders / registerDefaultLayoutLoaders (dagre, swimlane, and cose-bilkent only when includeLargeFeatures is on). This fires before any loader runs, so it's purely a name-mismatch against registered algorithms.","triggerScenarios":"A LayoutData with layoutAlgorithm: 'cose-bilkent' when the build excluded large features (the conditional spread at render.ts:49–56 omits it), or a typo like 'coseBilkent'/'dagre-d3', or a custom algorithm name never registered via registerLayoutLoaders.","commonSituations":"Using the `tiny`/slim build that sets includeLargeFeatures=false and thus drops cose-bilkent, a version where the default algorithm set changed, or an integration that sets layoutAlgorithm from config without validating against available loaders.","solutions":["Use one of the registered algorithm names: 'dagre' (default), 'swimlane', or 'cose-bilkent' (full build only).","If you need cose-bilkent, ensure your bundle includes large features (use the standard mermaid build, not the tiny one).","Register a custom loader with registerLayoutLoaders([{ name, loader }]) before rendering if you reference a custom algorithm.","Pre-validate with getRegisteredLayoutAlgorithm(layoutAlgorithm) which falls back to dagre instead of throwing."],"exampleFix":"// before (tiny build, large features excluded)\n{ ..., layoutAlgorithm: 'cose-bilkent' }\n// after\n{ ..., layoutAlgorithm: 'dagre' } // or use the full mermaid build","handlingStrategy":"validation","validationCode":"const KNOWN_ALGOS = new Set(['dagre', 'swimlane', 'cose-bilkent']);\nif (!KNOWN_ALGOS.has(layoutAlgorithm)) throw new Error(`unsupported layout algorithm: ${layoutAlgorithm}`);","typeGuard":"function isKnownLayoutAlgorithm(a: string): a is 'dagre' | 'swimlane' | 'cose-bilkent' { return a === 'dagre' || a === 'swimlane' || a === 'cose-bilkent'; }","tryCatchPattern":"try { render(data, svg); } catch (e) { if (/Unknown layout algorithm/.test(String(e))) { data.layoutAlgorithm = 'dagre'; render(data, svg); } else throw e; }","preventionTips":["Pre-resolve with getRegisteredLayoutAlgorithm() which falls back to dagre.","Use the full mermaid build if you need cose-bilkent.","Register custom loaders before referencing custom algorithm names."],"tags":["layout","render","configuration","registry"],"backgroundTag":null,"analyzedSha":"d93e9c88c01a599c062ee6a3f1462e3558ac6b90","analyzedAt":"2026-08-12T06:23:11.304Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}