Не работает docx.js
Пытаюсь разобраться с docx.js, есть код:
async function download () {
const doc = new Document({
sections: [
{
properties: {},
children: [
new docx.Paragraph({
children: [
new docx.TextRun("Hello World"),
new docx.TextRun({
text: "Foo Bar",
bold: true,
}),
new docx.TextRun({
text: "\tGithub is the best",
bold: true,
}),
],
}),
],
},
],
});
const blob = await docx.Packer.toBlob(doc);
const name = 'download.docx';
a.href = URL.createObjectURL(blob);
a.download = name;
a.click();
}
document.getElementById('download').addEventListener('click', download, false)
<!DOCTYPE html>
<html lang="en">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<button id="download" type="button">click</button>
</body>
</html>
<script src="https://unpkg.com/docx@8.0.3/build/index.js"></script>
Почему-то выходит ошибка:
dex.js:2 Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'Relationships')
at Object.xmlifyFile (index.js:2:321537)
at Object.compile (index.js:2:321269)
at Ia.<anonymous> (index.js:2:320739)
at Generator.next (<anonymous>)
at index.js:2:319772
at new Promise (<anonymous>)
at Sa (index.js:2:319517)
at Ia.toBlob (index.js:2:320682)
at HTMLButtonElement.download (js:45:36)
Как быть?
Источник: Stack Overflow на русском