ENOENT (errno 2)
errno 2
No such file or directory
Also searched as: No such file or directory, errno 2, ENOENT: no such file or directory, npm ERR! code ENOENT, FileNotFoundError
What it means
ENOENT, 'No such file or directory' (errno 2), means a path used by the program does not exist. It is one of the most common errors in shells, Node.js ('ENOENT: no such file or directory, open ...'), Python (FileNotFoundError) and build tools. Sometimes the missing piece is not the file you expect but an interpreter or library it needs.
Applies to: Linux, macOS (BSD errno), WSL, Docker containers
How to fix ENOENT (errno 2)
- Print the exact path from the error and check it with 'ls -la <path>'; watch for typos and letter case, since Linux paths are case-sensitive
- Check the current working directory with 'pwd'; relative paths resolve from where the program was started, not from the script's folder
- For 'npm ERR! enoent', run the command in the folder that contains package.json, then 'npm install' if node_modules is missing
- If a script exists but running it gives 'No such file or directory', check its shebang interpreter exists and fix Windows line endings with 'dos2unix script.sh'
- Check for broken symlinks with 'ls -l' and 'readlink -f <path>'
- Trace which path is missing with 'strace -f -e trace=openat,execve <command> 2>&1 | grep ENOENT'
- In Docker, make sure the file was copied into the image or mounted, and that paths match the container, not the host
Why it happens
Any path lookup that fails on a missing component returns ENOENT: deleted or never-created files, wrong working directory, broken symlinks, missing interpreters in a shebang, or files that exist only on the host and not in a container.
FAQ
Why does 'No such file or directory' appear when the file exists?
Usually the shebang points to a missing interpreter, the script has CRLF line endings, or a 32-bit binary is missing its loader. 'file script' and 'head -1 script' help identify it.
How do I fix ENOENT in Node.js?
Build paths with path.join(__dirname, 'file') instead of relative paths, and check the file exists in the deployed build.
Related errors
Source: Linux kernel errno.h · fixes written and reviewed by the editors (see our editorial policy)
Last updated: