Skip to content
Latchkey

Bun test "ENOENT" reading a fixture / file in CI

A test tried to open a file and got ENOENT because the path does not exist on the runner. This is usually a fixture referenced by a relative path that assumes a different working directory or an uncommitted file.

What this error means

bun test fails with "ENOENT: no such file or directory, open '...'" pointing at a fixture or data file the test reads.

Terminal
(fail) parser > parses sample
error: ENOENT: no such file or directory, open 'fixtures/sample.json'

Common causes

A relative fixture path tied to the working directory

The test opens fixtures/sample.json relative to the process cwd, which differs in CI from where you ran it locally.

The fixture is not committed or is gitignored

The fixture exists locally but was never committed, or a .gitignore excludes it, so it is absent on the runner.

How to fix it

Resolve fixture paths from the test file

  1. Build the path from import.meta.dir so it is independent of cwd.
  2. Confirm the fixture is committed and not gitignored.
  3. Re-run the test to confirm the file resolves.
src/parser.test.ts
import { join } from "path";
const p = join(import.meta.dir, "fixtures", "sample.json");
const data = await Bun.file(p).json();

Commit the fixture files

Add the fixtures to version control so the runner has them; check that no ignore rule excludes the directory.

Terminal
git add fixtures/sample.json
git commit -m "Add test fixture"

How to prevent it

  • Resolve fixture paths from import.meta.dir, not process cwd.
  • Commit all fixtures and verify they are not gitignored.
  • Keep test data close to the test file.

Related guides

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