Skip to content

Word Online cannot open .docx files generated with [email protected] (works fine in v8.1.3) #3289

@EedupugantiVenkatesh

Description

@EedupugantiVenkatesh

Summary

When generating .docx files using [email protected], the documents open perfectly in Neat Office and LibreOffice,
but fail to open in Microsoft Word Online and sometimes in desktop Word (Windows) with the error:

"We're sorry. We can't open this document because of an error in its contents."

Downgrading to [email protected] makes the exact same code and document structure work perfectly everywhere.

Environment

  • Node.js: v18.x / v20.x
  • OS: Windows
  • docx version: 9.5.1
  • Also tested on: 8.1.3 (works fine)

Reproduction

Minimal example:

const { Document, Packer, Paragraph, TextRun, Footer, AlignmentType, PageNumber } = require("docx");

const doc = new Document({
  sections: [{
    properties: {},
    headers: {
      default: new Footer({
        children: [
          new Paragraph({
            alignment: AlignmentType.RIGHT,
            children: [new TextRun({ children: ["Page ", PageNumber.CURRENT] })],
          }),
        ],
      }),
    },
    children: [new Paragraph("Hello world")],
  }],
});

Packer.toBuffer(doc).then(buffer => require("fs").writeFileSync("test.docx", buffer));


Result

 Works fine in Neat Office / LibreOffice.

 Word Online shows "Error in contents".

 Word Desktop prompts to repair.

Expected

Should open in all versions of Microsoft Word.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions