A common typo I've encountered from user templates is with the LINK command, where a user misses the brackets in the command's options:
// Was
{{ link {url: 'https://example.com'} }}
// Should be
{{ link ({url: 'https://example.com'}) }}
If the surrounding () happens to be missed, an exception gets thrown when calling createReport:
node_modules/docx-templates/lib/xml.js:90
var segments = str.split(options.literalXmlDelimiter);
^
TypeError: Cannot read properties of undefined (reading 'split')
at sanitizeText (node_modules/docx-templates/lib/xml.js:90:24)
at buildXml (node_modules/docx-templates/lib/xml.js:65:16)
at node_modules/docx-templates/lib/xml.js:77:20
at Array.forEach (<anonymous>)
at buildXml (node_modules/docx-templates/lib/xml.js:76:24)
at node_modules/docx-templates/lib/xml.js:77:20
at Array.forEach (<anonymous>)
at buildXml (node_modules/docx-templates/lib/xml.js:76:24)
at node_modules/docx-templates/lib/xml.js:77:20
at Array.forEach (<anonymous>)
This is invalid syntax according the docx-templates docs but it's an easy mistake to overlook and it's a hard failure and even with failFast: false gets thrown separately to other in-document errors. Ideally the failure would be softer, like how missing a mismatched or missing {{ end-for }} command occurs and not throw an unhandled exception, being incorporated into other document errors.
Otherwise, if feasible, avoid requiring the brackets in the syntax would avoid them being forgotten.
When reporting a bug, please provide:
A small reproducible example consisting of the code and .docx template you used.
A common typo I've encountered from user templates is with the
LINK
command, where a user misses the brackets in the command's options:If the surrounding
()
happens to be missed, an exception gets thrown when callingcreateReport
:This is invalid syntax according the docx-templates docs but it's an easy mistake to overlook and it's a hard failure and even with
failFast: false
gets thrown separately to other in-document errors. Ideally the failure would be softer, like how missing a mismatched or missing{{ end-for }}
command occurs and not throw an unhandled exception, being incorporated into other document errors.Otherwise, if feasible, avoid requiring the brackets in the syntax would avoid them being forgotten.
When reporting a bug, please provide:
Code:
template.docx
: