Cause 1 of 5
The path is relative, and the process started from a different directory.
A bare relative path resolves against process.cwd(), not against the file doing the reading. Anchor it to the module instead: path.join(import.meta.dirname, 'config.json') in ESM, or path.join(__dirname, 'config.json') in CommonJS.
Cause 2 of 5
The file genuinely is not there.
Log the resolved absolute path before opening it, then check that exact path with ls. In a container, the usual reason is a .dockerignore entry quietly dropping the file from the build context.
Cause 3 of 5
A parent directory does not exist on a write.
fs.writeFile creates files, never folders. Create the directory first: await fs.mkdir(path.dirname(target), { recursive: true }), which is a no-op when it already exists.
Cause 4 of 5
The name differs in case, or carries a hidden extension.
Linux is case-sensitive where your laptop is not. Windows also hides known extensions, so config.json on screen can be config.json.txt on disk — ls -la or dir /a shows the real name.
Cause 5 of 5
The ENOENT is about a command, not a data file.
spawn('somecli') throws ENOENT when the binary is not on PATH — the missing 'file' is the executable. Check with which somecli, and on Windows remember that .cmd shims need shell: true to be found.