Error: ENOENT: no such file or directory, open 'X'
ID: node/enoent-no-such-file
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 20 | active | — | — | — |
| 20 | active | — | — | — |
Root Cause
ENOENT on macOS x64 is most commonly caused by missing files after incomplete npm installs, broken symlinks, or path assumptions that break when moving between case-insensitive HFS+ (default) and case-sensitive APFS volumes. Since macOS is case-insensitive by default, this error less often stems from case mismatches and more often from genuinely missing files or stale symlinks.
genericWorkarounds
-
70% success Verify the file path exists and check for broken symlinks
Extract the path from the error message. Run 'ls -la <path>' and 'file <path>' to check if the target exists or is a broken symlink. If a symlink, recreate it with 'ln -s <real_target> <link_name>'.
Sources: https://nodejs.org/api/fs.html#fsaccesspath-mode-callback
-
65% success Delete node_modules and package-lock.json, then reinstall
rm -rf node_modules package-lock.json && npm install
Sources: https://nodejs.org/api/errors.html#common-system-errors
-
50% success Check for case-sensitive volume if using APFS case-sensitive format
Run 'diskutil info / | grep "File System Personality"' to check if the volume is case-sensitive. If so, audit file imports for case mismatches using 'find . -name "*.js" | xargs grep -n require'.
Dead Ends
Common approaches that don't work:
-
Running npm cache clean --force
95% fail
ENOENT indicates a missing filesystem path, not npm cache corruption. Clearing the cache does not create missing files, fix broken symlinks, or correct path references in code.
-
Reinstalling Xcode Command Line Tools
90% fail
Unless the ENOENT involves a native module that requires compilation tools, reinstalling Xcode CLT has no effect on missing file paths. This conflates build errors with path resolution errors.