mermaid-js/mermaid · error

Line ${origLineNo}: Empty node — expected a filename or dire

Error message

Line ${origLineNo}: Empty node — expected a filename or directory name after the box-drawing prefix

What it means

The treeView box-drawing preprocessor converts ASCII-tree input into indented text. After a branch character (├/└), the following dashes and spaces are skipped; whatever remains is the node name. If nothing remains, the line is a branch prefix with no content, so the input is rejected with the original line number.

Source

Thrown at packages/mermaid/src/diagrams/treeView/boxDrawingPreprocessor.ts:176

    const branchMatch = BRANCH_CHAR.exec(normalized);

    if (branchMatch?.index !== undefined) {
      // Has branch char → compute depth from column position
      const branchCol = branchMatch.index;
      const depth = Math.round(branchCol / segmentWidth) + 1;

      // Extract content: skip branch char, then dashes, then spaces
      let pos = branchCol + 1;
      while (pos < normalized.length && DASH_CHAR.test(normalized[pos])) {
        pos++;
      }
      while (pos < normalized.length && normalized[pos] === ' ') {
        pos++;
      }
      const content = normalized.slice(pos).trimEnd();

      if (!content) {
        throw new Error(
          `Line ${origLineNo}: Empty node — expected a filename or directory name after the box-drawing prefix`
        );
      }

      const indent = INDENT_UNIT.repeat(depth);
      outputLines.push(indent + content);
      outLineNo++;
      lineMap.set(outLineNo, origLineNo);
    } else if (/^[\s─━│┃└┗├┣]+$/.test(normalized)) {
      // Entire line is box-drawing decoration and whitespace — skip
      continue;
    } else if (ALL_BOX_CHARS.test(normalized)) {
      // Has box chars but no branch char — likely content containing a box char (e.g. "Section ─ A.txt")
      // Treat as root-level item
      outputLines.push(line);
      outLineNo++;
      lineMap.set(outLineNo, origLineNo);
    } else if (/^\s+/.test(normalized)) {

View on GitHub (pinned to d93e9c88c0)

Solutions

  1. Add the missing filename/directory name after the branch prefix on the reported line.
  2. Delete the empty branch line if no node is intended.
  3. Regenerate the tree source so every ├──/└── has a following name.
  4. Trim trailing decoration-only lines before parsing.

Example fix

// before
├── src
└──

// after
├── src
└── dist
Defensive patterns

Strategy: validation

Validate before calling

// Reject branch lines with no node content before feeding mermaid
for (let i = 0; i < lines.length; i++) {
  if (/^[│┃ ]*[├└┗]/.test(lines[i])) {
    const after = lines[i].replace(/^[│┃ ]*[├└┗]+[-─━ ]*/, '');
    if (!after.trim()) throw new Error(`Line ${i + 1}: empty node`);
  }
}

Type guard

const isEmptyNodeError = (e): boolean =>
  e instanceof Error && /Empty node/.test(e.message);

Try / catch

try {
  await mermaid.run({ nodes: [el] });
} catch (e) {
  if (e instanceof Error && /Empty node/.test(e.message)) {
    // parse the line number from the message and add a name or drop the line
  } else { throw e; }
}

Prevention

When it happens

Trigger: A line in box-drawing mode containing only a branch glyph and connectors/spaces, e.g. `├──` or `└── ` with no filename/directory after it.

Common situations: Trailing branch line from a copy-paste of `tree` output where the last entry was trimmed; manual editing that left an empty child; generated trees emitting a connector for a removed node; trailing whitespace mistaken for content.

Related errors


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