ENOENT
ENOENT: no such file or directory
Node.js was asked to open a file or folder that does not exist at that path.
What it means
Node.js's documentation describes ENOENT as an error commonly raised by file system operations when part of the path does not exist. The path in the error is the one Node tried. Read it closely: it is often not the path you meant.
Common causes
- A relative path, run from a different folder. Node resolves a relative path from the folder the command was started in (
process.cwd()), not from the file that contains it. The same script works from one folder and fails from another. - The file is not there. A typo, capital letters that do not match on a system that treats case as different, or a file that a step you have not run yet would create, such as build output.
- It exists on your computer but not on the server. The file is not in the repository, for example because
.gitignoreexcludes it, so a deploy never gets it. - npm, run in the wrong folder. npm reports ENOENT for
package.jsonwhen you run it outside the project folder.
Ways to fix it
- Build the path from the location of the file doing the reading, not from wherever the command was run:
path.join(__dirname, "data.json")in CommonJS, orimport.meta.dirnamein ES modules.
A prompt to fix it
Paste it into your AI coding tool and fill in the parts in angle brackets. It asks the tool to find the cause and show you before it changes anything.
Paste it, then fill in the <angle brackets>
I get: Error: ENOENT: no such file or directory, open '<the path in the error>'.
The command I ran, and the folder I ran it from: <paste>
Tell me:
1. The absolute path Node actually tried. If the path in the code is relative, work it out from the folder I ran the command in.
2. Whether that file exists, and if not, where the file really is.
3. Whether the file is committed to git, or ignored, or created by a step that has not run.
Then fix it so it does not depend on which folder the command runs from: build the path from the file's own location (__dirname or import.meta.dirname) instead of a bare relative path. Do not create an empty placeholder file to make the error go away.How to check it is fixed
- The command works when run from the project root, and from any other folder it is normally run from.
- If it failed on a server, check the file is in the repository:
git ls-files <path>prints the path if it is.
Tested prompts that help
- Hand It An Error — If the fix above does not do it, or your error is close to this one but not quite, this prompt hands your AI tool the whole error, what you expected, the last thing you changed and what you already ruled out, and makes it name the cause before it changes anything. Test log: Pass, ChatGPT (Pro), September 27, 2026; Pass, Claude.ai (Fable 5.1 Max), September 27, 2026.
Sources
Everything above comes from these pages. We read them on September 27, 2026; if one has changed since, it wins.