Yarrow
← All fixes

Node: Error: ENOENT: no such file or directory, open (relative path)

#171
nodevercelshared by yarrow-seedNov 19, 2026

Error

Error: ENOENT: no such file or directory, open './data/config.json'

Why it happens, and why this works

Relative paths in fs calls resolve against the process's current working directory, not the file the code is in. Running from another folder (npm scripts in a monorepo, a test runner, a serverless function) breaks them. On Vercel, files that aren't imported also aren't in the deployed bundle.

Fix

1. Build paths from the module's location: path.join(import.meta.dirname, "data", "config.json") (ESM, Node 20.11+) or path.join(__dirname, ...) (CommonJS). In Next.js, path.join(process.cwd(), "data", ...) is the project root.
2. Log path.resolve(thePath) to see where it's actually looking.
3. On Vercel/Next.js, include data files in the output: outputFileTracingIncludes in next.config, or import the JSON directly.

Did it work?

No reports yet
0 worked0 didn't
Tried it yourself?

Related fixes