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

Node.js · updated 2026-11-03

Thrown by fs calls (readFile, open, stat, readdir) and by child_process.spawn when the file or command is missing. The path in the message is the exact one Node tried, after resolving it against the current working directory.

node:internal/fs/promises:639
  return new FileHandle(await PromisePrototypeCall(binding.openFileHandle, binding, path, flags, mode));
                                                     ^

Error: ENOENT: no such file or directory, open '/app/config.json'
    at async open (node:internal/fs/promises:639:25)
    at async Object.readFile (node:internal/fs/promises:1242:14)
    at async loadConfig (file:///app/src/config.js:8:16) {
  errno: -2,
  code: 'ENOENT',
  syscall: 'open',
  path: '/app/config.json'
}

Quick fix

Read the path in the message: that is where Node looked. If it is relative to the folder you started the process from, build it from the module's own location instead, and confirm the file exists in the build or container that is running.

  1. Copy the path from the error and run ls -la on it inside the same environment (container, server or CI job).
  2. If the path came from a relative string like ./data/x.json, resolve it from the module with new URL or path.join(__dirname, ...).
  3. Check that the build or Docker image copies the file: a .dockerignore, files list in package.json or a missing COPY step can drop it.
  4. For spawn ENOENT, check that the command is installed and on the PATH of the process, not just your shell.
  5. If the file is optional, catch the error and check err.code === "ENOENT" instead of letting it crash.
typescript
import { readFile } from 'node:fs/promises';

// Resolve next to this module, not the folder the process started in
const configUrl = new URL('../config.json', import.meta.url);

export async function loadConfig() {
  try {
    return JSON.parse(await readFile(configUrl, 'utf8'));
  } catch (err) {
    if ((err as NodeJS.ErrnoException).code === 'ENOENT') return {}; // optional file
    throw err;
  }
}

Why it happens

A relative path resolved against the wrong folder

fs resolves relative paths against process.cwd(), the folder the process was started from. The same code works from the project root and fails from a process manager, cron job or test runner that starts elsewhere.

The file never made it into the build

Bundlers only include files they can trace from imports. A JSON or template read with fs at runtime is invisible to them, and Docker images or serverless bundles ship without it unless it is copied explicitly.

A typo or case mismatch

macOS file systems are case-insensitive by default and most Linux ones are not, so Config.json and config.json are the same file on a laptop and different files in production.

A command that is not installed (spawn ENOENT)

child_process.spawn('ffmpeg') fails with spawn ffmpeg ENOENT when the binary is missing or not on the PATH the process inherited, which is often shorter than your interactive shell's PATH.

Other fixes

  • Log process.cwd() at startup when a path works locally and fails in one environment.
  • Create directories before writing with mkdir(dir, { recursive: true }).
  • For spawn ENOENT on Windows, scripts like npm need shell: true or the .cmd suffix.

Same error, other wording

  • Error: ENOENT: no such file or directory, stat '/app/public/index.html'
  • Error: ENOENT: no such file or directory, scandir './uploads'
  • Error: spawn ffmpeg ENOENT

Let your coding agent catch the next one

Runheed records this error in production with the stack trace, the breadcrumbs before it and the agent session that shipped the code, and serves it to Claude Code, Cursor or any MCP client. With it connected, you can ask:

> Find the ENOENT errors from the last deploy, list each missing path and the code that read it, and change those reads to resolve paths from the module instead of process.cwd().

Plans from $29/moSee what your agent readsSee the setupCancel any time from the billing portal

Related errors

References: Node.js errors: common system errors (ENOENT), Node.js file system: file paths