n8n-io/n8n · error · Error
Failed to parse docx
Error message
Failed to parse docx "${attachment.fileName}": ${message} What it means
mammoth's extractRawText threw while parsing the (size-guard-passed) docx buffer — the file is structurally invalid OOXML: corrupted ZIP container, missing document.xml, or a non-docx file renamed to .docx. The message wraps the underlying parser error for diagnosis.
Solutions
- Verify the file opens in Word/LibreOffice — a corrupt export or truncated upload is the usual cause
- Re-save or re-export the document to produce a clean docx
- If the file is actually another format (e.g. old .doc), convert it to .docx before attaching
Defensive patterns
Strategy: try-catch
When it happens
Trigger: Thrown at packages/@n8n/instance-ai/src/parsers/docx-parser.ts:35 when the library encounters an invalid state.
Common situations: See trigger scenarios.
Understand the failure class
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
AI-assisted analysis of n8n-io/n8n@5ac6606e81 (2026-08-12).
Data as JSON: /api/errors/815924898e397554.
Report an issue: GitHub.
Appendix: source
Thrown at packages/@n8n/instance-ai/src/parsers/docx-parser.ts:35
export async function extractDocxText(attachment: AttachmentInfo): Promise<DocxExtractionResult> {
const decoded = Buffer.from(attachment.data, 'base64');
if (decoded.length > MAX_DECODED_SIZE_BYTES) {
throw new Error(formatSizeLimitMessage(decoded.length));
}
assertOoxmlWithinBounds(decoded, attachment.fileName);
const mammoth = await import('mammoth');
const extractRawText = mammoth.extractRawText ?? mammoth.default?.extractRawText;
if (typeof extractRawText !== 'function') {
throw new Error('mammoth.extractRawText is not available');
}
let raw: { value: string };
try {
raw = await extractRawText({ buffer: decoded });
} catch (error) {
const message = error instanceof Error ? error.message : 'unknown error';
throw new Error(`Failed to parse docx "${attachment.fileName}": ${message}`);
}
const text = raw.value?.trim() ?? '';
if (!text) {
throw new Error(`docx "${attachment.fileName}" contains no extractable text.`);
}
if (text.length > MAX_RESULT_CHARS) {
return { text: text.slice(0, MAX_RESULT_CHARS), truncated: true };
}
return { text, truncated: false };
}
View on GitHub (pinned to 5ac6606e81)