Skip to content
Latchkey

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

  1. Build an absolute path from the module location instead of relying on cwd.
  2. 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

  1. Confirm the file is committed or generated earlier in the job.
  2. 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

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →