mammoth
semver
>=1.11.0postconditions14functions7last verified2026-06-24coverage score78%Postconditions: what we check
- convertToHtml · file-read-errorerrorWhenFile path does not exist, cannot be read, or input options are invalidThrows
Error (ENOENT, EACCES, or 'Could not find file in options')Required handlingCaller MUST wrap convertToHtml() in try-catch to handle file-not-found and permission errors.costmediumin prodimmediate exceptionusers seeservice unavailablevisibilityvisible - convertToHtml · corrupt-docx-errorerrorWhenBuffer contains invalid or corrupt docx/zip dataThrows
Error (zip parsing error)Required handlingCaller MUST wrap convertToHtml() in try-catch to handle corrupt or invalid docx files.costmediumin prodimmediate exceptionusers seeservice unavailablevisibilityvisibleSources[1] - extractRawText · file-read-errorerrorWhenFile path does not exist, cannot be read, or input options are invalidThrows
Error (ENOENT, EACCES, or 'Could not find file in options')Required handlingCaller MUST wrap extractRawText() in try-catch to handle file-not-found and permission errors.costmediumin prodimmediate exceptionusers seeservice unavailablevisibilityvisible - extractRawText · corrupt-docx-errorerrorWhenBuffer contains invalid or corrupt docx/zip dataThrows
Error (zip parsing error)Required handlingCaller MUST wrap extractRawText() in try-catch to handle corrupt or invalid docx files.costmediumin prodimmediate exceptionusers seeservice unavailablevisibilityvisibleSources[1] - convertToMarkdown · converttomarkdown-file-read-errorerrorWhenFile path does not exist, cannot be read, or input options are missingThrows
Error (ENOENT, EACCES, or 'Could not find file in options')Required handlingCaller MUST wrap convertToMarkdown() in try-catch. Error propagates from unzip.js when the file path does not exist (ENOENT), cannot be accessed (EACCES), or when no valid input type is provided. Without handling, a missing upload causes an unhandled promise rejection that crashes the processing pipeline.costmediumin prodimmediate exceptionusers seeservice unavailablevisibilityvisible - convertToMarkdown · converttomarkdown-corrupt-docx-errorerrorWhenBuffer contains invalid or corrupt docx/zip dataThrows
Error (zip parsing error from JSZip.loadAsync)Required handlingCaller MUST wrap convertToMarkdown() in try-catch. Corrupt .docx files are common when processing user-uploaded documents. JSZip.loadAsync() rejects when the input is not a valid ZIP file (all .docx are ZIP archives). The error propagates up through unzip.openZip() without transformation.costmediumin prodimmediate exceptionusers seeservice unavailablevisibilityvisible - convertToMarkdown · converttomarkdown-deprecated-usewarningWhenconvertToMarkdown is called in new code (not legacy maintenance) instead of converting to HTML first and using a dedicated HTML-to-Markdown libraryReturnsMarkdown output in result.value, but the implementation is not maintained. The official recommendation is to call convertToHtml() and pipe through a dedicated library (e.g. turndown) for better results.Required handlingSHOULD migrate to convertToHtml() + turndown pattern. The Mammoth maintainer has explicitly deprecated this function. New code should not use it. Existing callers should migrate to avoid quality regressions as the Markdown support is no longer improved.costlowin proddegraded serviceusers seedegraded performancevisibilitysilentSources[1]
- embedStyleMap · embedstylemap-file-read-errorerrorWhenInput file path does not exist, is unreadable, or input options are missingThrows
Error (ENOENT, EACCES, or 'Could not find file in options')Required handlingCaller MUST wrap embedStyleMap() in try-catch. The function opens the .docx via unzip.openZip(), which throws when the file path is missing or the buffer is invalid. Document transformation pipelines that pre-process uploaded .docx files for style consistency must handle missing-file scenarios.costmediumin prodimmediate exceptionusers seeservice unavailablevisibilityvisible - embedStyleMap · embedstylemap-corrupt-docx-errorerrorWhenInput buffer contains invalid or corrupt docx/zip dataThrows
Error (zip parsing error from JSZip.loadAsync)Required handlingCaller MUST wrap embedStyleMap() in try-catch. The function reads the .docx ZIP structure to inject the style map. A corrupt archive causes JSZip to reject. This is critical in document pre-processing pipelines that modify uploaded docs before storage — corrupted inputs must be caught and rejected early.costmediumin prodimmediate exceptionusers seeservice unavailablevisibilityvisible - embedStyleMap · embedstylemap-result-not-savedwarningWhenembedStyleMap() resolves successfully but the caller does not call toBuffer() or toArrayBuffer() to persist the modified document, OR does not write the returned buffer to storage (file system or object store)ReturnsPromise resolves to {toArrayBuffer(), toBuffer()} — if the result is not written to storage, the embedded style map is silently lost. The original file is NOT modified in place — a new document must be explicitly saved.Required handlingCaller MUST call docx.toBuffer() or docx.toArrayBuffer() on the resolved value AND write it to persistent storage. The function does not overwrite the original file. If the result is not persisted, the style map embedding is silently lost and future conversions will use the original document without the embedded map.costlowin prodsilent failureusers seelost datavisibilitysilent
- readAsArrayBuffer · readasarraybuffer-image-missing-from-ziperrorWhenThe embedded image referenced in the .docx relationships is missing from the underlying zip archive (corrupt or hand-edited .docx where the image part was deleted but the relationship/reference remained), OR the relationship resolves to an invalid zip path. JSZip's zipFile.file(name) returns null and the subsequent .async("uint8array") access throws TypeError.Throws
TypeError (Cannot read properties of null (reading 'async')) from JSZipRequired handlingCaller MUST wrap image.readAsArrayBuffer() in try-catch inside the imageConverter callback (or attach .catch() to the returned Promise). Without handling, the rejected Promise propagates up through the imgElement wrapper and surfaces as a conversion-level rejection that crashes the entire convertToHtml/convertToMarkdown call — one missing image breaks the whole document conversion.costmediumin prodimmediate exceptionusers seeservice unavailablevisibilityvisible - readAsBase64String · readasbase64string-image-missing-from-ziperrorWhenThe embedded image referenced in the .docx relationships is missing from the underlying zip archive, OR the relationship resolves to an invalid zip path. JSZip's zipFile.file(name) returns null and the subsequent .async() access throws. This is the common failure mode for hand-edited or partially-corrupted .docx files and propagates through the default dataUri converter.Throws
TypeError (Cannot read properties of null (reading 'async')) from JSZipRequired handlingCaller MUST wrap image.readAsBase64String() in try-catch inside the imageConverter callback, or attach .catch() to the returned Promise. Custom imgElement callbacks that use readAsBase64String to build data-URI src attributes must handle the rejection — without handling, one corrupt image embed crashes the entire convertToHtml/convertToMarkdown pipeline and the user sees a 500/unhandled rejection instead of a partial document with a warning.costmediumin prodimmediate exceptionusers seeservice unavailablevisibilityvisible - readAsBuffer · readasbuffer-image-missing-from-ziperrorWhenThe embedded image referenced in the .docx relationships is missing from the underlying zip archive, OR the relationship path is invalid. JSZip's zipFile.file(name) returns null and the .async() access throws TypeError before Buffer.from is reached.Throws
TypeError (Cannot read properties of null (reading 'async')) from JSZipRequired handlingCaller MUST wrap image.readAsBuffer() in try-catch inside the imageConverter callback, or attach .catch() to the returned Promise. An uncaught rejection propagates through the imgElement wrapper and crashes the whole document conversion.costmediumin prodimmediate exceptionusers seeservice unavailablevisibilityvisible - readAsBuffer · readasbuffer-browser-no-buffer-polyfillwarningWhenimage.readAsBuffer() is called from browser code without a Buffer polyfill (e.g. mammoth bundled into a frontend app without webpack/vite Buffer shim). The underlying options.readImage() resolves an ArrayBuffer, then Buffer.from throws ReferenceError because Buffer is not a global in browsers.Throws
ReferenceError (Buffer is not defined) — browsers without polyfillRequired handlingCaller MUST either (a) avoid readAsBuffer() in browser code and use readAsArrayBuffer() or readAsBase64String() instead, OR (b) wrap the call in try-catch and supply a polyfilled fallback. The mammoth README explicitly warns "This is not supported in browsers unless a Buffer polyfill has been used." Custom imageConverters shipped in isomorphic libraries must guard this method or ship a polyfill.costlowin prodimmediate exceptionusers seeservice unavailablevisibilityvisible
Sources
Every postcondition cites at least one of these. Grouped by source type; numbered to match the footnotes above.
Source code
- [1]raw.githubusercontent.com/mwilliamson/mammoth.js/mastermwilliamson/mammoth.js · README.md
- [2]github.com/mwilliamson/mammoth.js/blobmwilliamson/mammoth.js · unzip.js
- [3]github.com/mwilliamson/mammoth.js/blobmwilliamson/mammoth.js · zipfile.js
- [4]github.com/mwilliamson/mammoth.js/blobmwilliamson/mammoth.js · index.js
- [5]github.com/mwilliamson/mammoth.js/blobmwilliamson/mammoth.js · documents.js
- [6]github.com/mwilliamson/mammoth.js/blobmwilliamson/mammoth.js · images.js
Research notes
Curator notes from SOURCES.md captured when the profile was written so you can verify the reasoning, not just the rules.
Sources — mammoth
Last verified: 2026-04-02
Documentation
| URL | Fetched | Summary |
|---|---|---|
| https://raw.githubusercontent.com/mwilliamson/mammoth.js/master/README.md | 2026-04-02 | Official README; shows .catch() usage for both convertToHtml and extractRawText; confirms promise rejection on errors |
| https://github.com/mwilliamson/mammoth.js/blob/master/lib/unzip.js | 2026-04-02 | Source confirms promises.reject(new Error("Could not find file in options")) for invalid input |
Security
| CVE | Description | Fixed Version |
|---|---|---|
| CVE-2025-11849 | Directory traversal via crafted docx image links | >=1.11.0 |
Source: https://security.snyk.io/vuln/SNYK-JS-MAMMOTH-13554470
Real-World Usage
- outline/outline (⭐ 37k): Uses
mammoth.convertToHtml({ buffer })for Word document import - 55 runtime-dep repos total in corpus
Need a different package?
Request a profile