{"record":{"id":"b76647fd514cb340","repo":"Mintplex-Labs/anything-llm","slug":"failed-to-load-pdf-parse-please-install-it-with-e","errorCode":null,"errorMessage":"Failed to load pdf-parse. Please install it with eg. `npm install pdf-parse`.","messagePattern":"Failed to load pdf-parse\\. Please install it with eg\\. `npm install pdf-parse`\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"critical","filePath":"collector/processSingleFile/convert/asPDF/PDFLoader/index.js","lineNumber":90,"sourceCode":"          source: this.filePath,\n          pdf: {\n            version,\n            info: meta?.info,\n            metadata: meta?.metadata,\n            totalPages: pdf.numPages,\n          },\n        },\n      },\n    ];\n  }\n\n  async getPdfJS() {\n    try {\n      const pdfjs = await import(\"pdf-parse/lib/pdf.js/v1.10.100/build/pdf.js\");\n      return { getDocument: pdfjs.getDocument, version: pdfjs.version };\n    } catch (e) {\n      console.error(e);\n      throw new Error(\n        \"Failed to load pdf-parse. Please install it with eg. `npm install pdf-parse`.\"\n      );\n    }\n  }\n}\n\nmodule.exports = PDFLoader;\n","sourceCodeStart":72,"sourceCodeEnd":98,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/526360e320da9d1b36074be5ed64fe76e5bbfbbd/collector/processSingleFile/convert/asPDF/PDFLoader/index.js#L72-L98","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before — throws on missing/renamed submodule path\nconst pdfjs = await import(\"pdf-parse/lib/pdf.js/v1.10.100/build/pdf.js\");\n\n// after — guard version, fall back to top-level export\nasync getPdfJS() {\n  try {\n    return await import(\"pdf-parse/lib/pdf.js/v1.10.100/build/pdf.js\")\n      .then((m) => ({ getDocument: m.getDocument, version: m.version }));\n  } catch {\n    const pdfjs = require(\"pdf-parse\"); // top-level fallback\n    return { getDocument: pdfjs.getDocument, version: pdfjs.version };\n  }\n}","handlingStrategy":"fallback","validationCode":"// Verify the deep submodule path exists before relying on PDF parsing\nconst fs = require(\"fs\");\nconst path = require(\"path\");\nfunction pdfParseReady() {\n  try {\n    return fs.existsSync(\n    path.join(process.cwd(), \"node_modules/pdf-parse/lib/pdf.js/v1.10.100/build/pdf.js\")\n    );\n  } catch { return false; }\n}","typeGuard":null,"tryCatchPattern":"try {\n  await new PDFLoader(filePath).load();\n} catch (e) {\n  if (/Failed to load pdf-parse/.test(e.message)) {\n    // surface an actionable, installable error to the user; do not silently skip the file\n    throw new Error(\"PDF support is not installed on the collector. Run the project's install command, then retry.\");\n  }\n  throw e;\n}","preventionTips":["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."],"tags":["dependency","pdf","module-load","pdf-parse"],"backgroundTag":null,"analyzedSha":"526360e320da9d1b36074be5ed64fe76e5bbfbbd","analyzedAt":"2026-08-13T01:45:47.170Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}