mermaid-js/mermaid · error · Error

Items without section detected, found section ("${nodes[i].l

Error message

Items without section detected, found section ("${nodes[i].label}")

What it means

Thrown by getLatestSection in the kanban db while walking nodes in reverse to find the last section header. The code records the section level from nodes[0].level; if it then encounters a node whose level is lower than that section level before any section was identified as lastSection, it means kanban items (children) appear without a preceding section (column) to belong to. Kanban requires every item to live under a section.

Source

Thrown at packages/mermaid/src/diagrams/kanban/kanbanDb.ts:39

/*
 * if your level is the section level return null - then you do not belong to a level
 * otherwise return the current section
 */
const getSection = (level: number) => {
  if (nodes.length === 0) {
    // console.log('No nodes');
    return null;
  }
  const sectionLevel = nodes[0].level;
  let lastSection = null;
  for (let i = nodes.length - 1; i >= 0; i--) {
    if (nodes[i].level === sectionLevel && !lastSection) {
      lastSection = nodes[i];
      // console.log('lastSection found', lastSection);
    }
    // console.log('HERE', nodes[i].id, level, nodes[i].level, sectionLevel);
    if (nodes[i].level < sectionLevel) {
      throw new Error('Items without section detected, found section ("' + nodes[i].label + '")');
    }
  }
  if (level === lastSection?.level) {
    return null;
  }

  // No found
  return lastSection;
};

const getSections = function () {
  return sections;
};

const getData = function () {
  const edges = [] as Edge[];
  const _nodes: KanbanNode[] = [];

View on GitHub (pinned to d93e9c88c0)

Solutions

  1. Ensure the diagram opens with a section header (top-level node) and that every task item is indented underneath a section.
  2. Normalize indentation to spaces only and verify each item's level is greater than its section's level.
  3. Re-read the kanban syntax docs and confirm the section-then-items structure.
  4. Remove items one at a time to find the offending node, then re-indent it correctly.

Example fix

// before (item before any section)
kanban
  - Task with no section
  section A
    - Task A1

// after
kanban
  section A
    - Task A1
Defensive patterns

Strategy: validation

Validate before calling

// Validate kanban structure before render: every item must have a section ancestor.
// Pseudocode over parsed nodes:
function validateKanbanSections(nodes: {level:number;id:string}[]): string[] {
  const errors: string[] = [];
  const sectionLevel = nodes[0]?.level;
  let seenSection = false;
  for (const n of nodes) {
    if (n.level === sectionLevel) seenSection = true;
    if (n.level < sectionLevel && !seenSection) {
      errors.push(`Item ${n.id} appears before any section header`);
    }
  }
  return errors;
}

Try / catch

try {
  await mermaid.render('g', diagramText);
} catch (e) {
  if (e instanceof Error && /Items without section detected/.test(e.message)) {
    showUserError('Every kanban item must be placed under a section header. Add a section before your items.');
  } else {
    throw e;
  }
}

Prevention

When it happens

Trigger: A kanban diagram body that lists task items before declaring any section/column header; or indentation in the source makes an item's level lower than the section level, breaking the parent/child expectation.

Common situations: Author forgets the section header line; copy-paste of items from another diagram drops the section; markdown indentation off by one tab/spaces so the parser mis-ranks node levels; mixing tabs and spaces in the kanban source.

Related errors


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