can1357/oh-my-pi · error · Error

Invalid DOCX: missing document body

Error message

Invalid DOCX: missing document body

What it means

After locating word/document.xml, convertToHtml() parses it and requires a <w:body> child element, which contains the document's block content. A document.xml without a body is structurally invalid for OOXML, so rendering cannot proceed and this error is thrown.

Source

Thrown at packages/utils/src/docx/converter.ts:678

	if (!documentXml) throw new Error("Invalid DOCX: missing word/document.xml");
	const context: ConversionContext = {
		entries,
		relationships: parseRelationships(archiveEntryText(entries, "word/_rels/document.xml.rels")),
		contentTypes: parseContentTypes(archiveEntryText(entries, "[Content_Types].xml")),
		styles: parseStyles(archiveEntryText(entries, "word/styles.xml")),
		numbering: parseNumbering(archiveEntryText(entries, "word/numbering.xml")),
		messages: [],
		warnedStyles: new Set(),
		customStyles: parseCustomStyles(options.styleMap),
		includeDefaultStyleMap: options.includeDefaultStyleMap !== false,
		convertImage: options.convertImage ?? defaultImageConverter(),
		footnotes: parseFootnotes(archiveEntryText(entries, "word/footnotes.xml")),
		usedFootnotes: [],
		footnoteOrdinals: new Map(),
	};
	const document = parseXml(documentXml);
	const body = firstChild(document, "body");
	if (!body) throw new Error("Invalid DOCX: missing document body");
	const value = renderBlocks(await parseBlocks(childElements(body), context)) + (await renderFootnotes(context));
	return { value, messages: context.messages };
}

View on GitHub (pinned to 9690622007)

Solutions

  1. Regenerate or fix the DOCX so word/document.xml contains a <w:body> element (use a library like docx or save from Word).
  2. Inspect the archive: extract and view word/document.xml to confirm the <w:document ...><w:body> structure.
  3. If generating DOCX programmatically, emit the body even for empty documents: <w:body></w:body>.
  4. Re-save the file via LibreOffice headless (`soffice --convert-to docx`) to normalize the XML structure.

Example fix

// before (generated document.xml)
<?xml version="1.0"?><w:document xmlns:w="..."></w:document>

// after
<?xml version="1.0"?><w:document xmlns:w="..."><w:body><w:p/></w:body></w:document>
Defensive patterns

Strategy: validation

Validate before calling

import { readArchiveEntries, archiveEntryText } from "./xml-helpers"; // same helpers the library uses
const entries = await readArchiveEntries({ bytes, format: "zip" });
const doc = archiveEntryText(entries, "word/document.xml");
if (!doc || !/<w:body[\s>]/.test(doc)) throw new Error("DOCX document.xml has no <w:body>");

Try / catch

try {
  return await convertToHtml(input);
} catch (err) {
  if (err instanceof Error && err.message === "Invalid DOCX: missing document body") {
    // regenerate/normalize the file with soffice --convert-to docx, or reject the document
  } else throw err;
}

Prevention

When it happens

Trigger: Calling convertToHtml() on a DOCX whose word/document.xml lacks a <w:body> element: hand-crafted or programmatically generated XML missing the body, an XML document saved with the wrong root, or a file where document.xml is actually a non-document OOXML part.

Common situations: Generating DOCX with a custom writer that emits <w:document> without <w:body>; template post-processing that strips the body; zipping an arbitrary XML file as word/document.xml to satisfy format checks.

Related errors


AI-assisted analysis of can1357/oh-my-pi@9690622007 (2026-08-31). Data as JSON: /api/errors/8c994d04144fefd8. Report an issue: GitHub.