Mintplex-Labs/anything-llm · critical · Error
Failed to load pdf-parse. Please install it with eg. `npm in
Error message
Failed to load pdf-parse. Please install it with eg. `npm install pdf-parse`.
What it means
Thrown by PDFLoader.getPdfJS in collector/processSingleFile/convert/asPDF/PDFLoader/index.js:90 when the dynamic import of "pdf-parse/lib/pdf.js/v1.10.100/build/pdf.js" rejects. The catch wraps the original error (which is also console.error'd) and rethrows this friendlier message. The original cause is usually that pdf-parse is not installed, was hoisted incorrectly, the pinned internal path changed in a newer pdf-parse release, or the module file is missing from node_modules.
Source
Thrown at collector/processSingleFile/convert/asPDF/PDFLoader/index.js:90
source: this.filePath,
pdf: {
version,
info: meta?.info,
metadata: meta?.metadata,
totalPages: pdf.numPages,
},
},
},
];
}
async getPdfJS() {
try {
const pdfjs = await import("pdf-parse/lib/pdf.js/v1.10.100/build/pdf.js");
return { getDocument: pdfjs.getDocument, version: pdfjs.version };
} catch (e) {
console.error(e);
throw new Error(
"Failed to load pdf-parse. Please install it with eg. `npm install pdf-parse`."
);
}
}
}
module.exports = PDFLoader;
View on GitHub (pinned to 526360e320)
Solutions
- Run `npm install pdf-parse` (or the project's documented install command) in collector/.
- Pin pdf-parse to the version the loader expects so lib/pdf.js/v1.10.100/build/pdf.js exists — check the package.json the project ships.
- Rebuild the Docker image from a clean layer to ensure node_modules is complete.
- Inspect the original error printed above the friendly message — it names the actual module path that failed.
Example fix
// before — throws on missing/renamed submodule path
const pdfjs = await import("pdf-parse/lib/pdf.js/v1.10.100/build/pdf.js");
// after — guard version, fall back to top-level export
async getPdfJS() {
try {
return await import("pdf-parse/lib/pdf.js/v1.10.100/build/pdf.js")
.then((m) => ({ getDocument: m.getDocument, version: m.version }));
} catch {
const pdfjs = require("pdf-parse"); // top-level fallback
return { getDocument: pdfjs.getDocument, version: pdfjs.version };
}
} Defensive patterns
Strategy: fallback
Validate before calling
// Verify the deep submodule path exists before relying on PDF parsing
const fs = require("fs");
const path = require("path");
function pdfParseReady() {
try {
return fs.existsSync(
path.join(process.cwd(), "node_modules/pdf-parse/lib/pdf.js/v1.10.100/build/pdf.js")
);
} catch { return false; }
} Try / catch
try {
await new PDFLoader(filePath).load();
} catch (e) {
if (/Failed to load pdf-parse/.test(e.message)) {
// surface an actionable, installable error to the user; do not silently skip the file
throw new Error("PDF support is not installed on the collector. Run the project's install command, then retry.");
}
throw e;
} Prevention
- Run the project's install command (npm install) in collector/ before processing PDFs.
- Pin pdf-parse to the version whose internal lib/pdf.js/v1.10.100 path the loader expects — do not float major.
- Rebuild Docker images from clean layers so node_modules is complete.
- Read the original error printed above the friendly message — it identifies the missing path.
When it happens
Trigger: Loading any PDF when pdf-parse is missing from node_modules; running against a pdf-parse version that no longer ships lib/pdf.js/v1.10.100/build/pdf.js; a broken/partial npm install; Docker image built without dev/optional deps; monorepo hoisting left the deep path unresolvable.
Common situations: Fresh clone where `npm install` was skipped or run with --production/--omit=optional; pdf-parse bumped to a version that restructured its internals; container image pruned node_modules; pnpm/yarn-workspace hoisting hid the submodule path.
Related errors
AI-assisted analysis of Mintplex-Labs/anything-llm@526360e320 (2026-08-13).
Data as JSON: /api/errors/b76647fd514cb340.
Report an issue: GitHub.