TL;DR: If you're seeing ENOENT related to 05-versions-space.pdf while using pdf-parse in Node.js - it's not your fault. It's hidden debug logic inside the library. Here's the fix.
🧩 The Problem: A Mysterious Crash
I was building a pdf parsing backend in Node.js. Everything was working until I added pdf-parse to extract text from uploaded PDFs.
My code was clean:
import fs from "fs/promises";
import pdfParser from "pdf-parse";
const buffer = await fs.readFile("uploads/file.pdf");
const data = await pdfParser(buffer);
console.log(data.text);
Then suddenly… boom:
Error: ENOENT: no such file or directory, open 'C:\\...\\test\\data\\05-versions-space.pdf'
What file? What path? I never wrote that!
🤯 The Real Culprit
The problem isn't your code - it's debug logic inside pdf-parse itself.
If you peek inside node_modules/pdf-parse/index.js, you'll find this block:
let isDebugMode = !module.parent;
if (isDebugMode) {
const filePath = path.join(__dirname, "test/data/05-versions-space.pdf");
const dataBuffer = fs.readFileSync(filePath);
...
}
🟥 If this runs, and the file doesn't exist (and it won't), the app crashes.
✅ The Fixes
🔧 Option 1: Create the Missing File
Quickest workaround:
1- Create this folder:
mkdir -p node_modules/pdf-parse/test/data
2- Add any valid PDF file to it and name it:
05-versions-space.pdf
✅ Done. Your app won't crash anymore.
🛡️ Option 2: Permanently Disable Debug Mode (Recommended)
You can patch the module to prevent future issues:
1- Install patch-package:
npm install patch-package
2- Edit node_modules/pdf-parse/index.js:
Change this line:
let isDebugMode = !module.parent;
To:
let isDebugMode = false;
3- Save the file and run:
npx patch-package pdf-parse
4- Add this to your package.json scripts to ensure the patch survives reinstalls:
"scripts": {
"postinstall": "patch-package"
}
💡 Lessons Learned
- Not all bugs are in your code.
- Always check a library's index.js if you're getting unexpected behavior.
- Defensive code matters. Production libraries should avoid running debug logic by default.
🧠 Final Thoughts
If you're building a backend using pdf-parse, make sure you:
❌ Disable the debug mode
📁 Handle file paths using path.resolve() to avoid OS path issues
🛡️ Always wrap file reads in try/catch
Like this post? Bookmark it or share with your dev group - because these "WTF" bugs deserve visibility.
Have you faced a similar issue with another library? Drop a comment, and let's debug together.
Top comments (0)