Node "ENOENT no such file or directory, open" in CI - Fix the Missing File
ENOENT on open means your code tried to read a file at a path that does not exist on the CI runner, frequently because of a relative path resolved from the wrong cwd.
What this error means
A node process throws Error: ENOENT: no such file or directory, open '<path>' when reading config, fixtures, or assets. It works locally but the file is missing in CI.
node
Error: ENOENT: no such file or directory, open './config/settings.json'
at Object.openSync (node:fs:603:3)
at readFileSync (node:fs:471:35) {
errno: -2, code: 'ENOENT', syscall: 'open'
}Common causes
A relative path resolved from the wrong working directory
fs resolves relative paths against process.cwd(), which in CI may differ from where the file actually lives.
The file is gitignored or generated
The file exists locally but is not committed or not produced in CI, so it is absent on a clean checkout.
How to fix it
Resolve paths relative to the module
- Build an absolute path from the module location instead of relying on cwd.
- Use that absolute path for the read.
JavaScript
import { fileURLToPath } from 'node:url';
import { dirname, join } from 'node:path';
const here = dirname(fileURLToPath(import.meta.url));
const file = join(here, 'config', 'settings.json');Make sure the file exists in CI
- Confirm the file is committed or generated earlier in the job.
- Add the generation step before the read if it is produced.
How to prevent it
- Resolve runtime file paths from import.meta.url or __dirname, commit required fixtures, and avoid depending on the CI working directory matching your local shell.
Related guides
Node "ENOENT open .env" Missing Env File at Runtime in CI - Fix ItFix a Node.js missing .env file at runtime in CI by providing the variables through workflow env or secrets i…
Node "spawn ENOENT" for a Child Process in CI - Fix the Missing ExecutableFix the Node.js "spawn ENOENT" child-process error in CI by installing the missing executable or correcting t…
Node "Error: Cannot find module 'X'" in CI - Fix Module ResolutionFix the Node.js "Error: Cannot find module" crash in CI by correcting the path, extension, or build output th…