ENOENT
node
path_handling
ai_generated
true
Error: ENOENT: no such file or directory — Node.js path resolution fails with spaces
ID: node/enoent-space-in-project-path
88%Fix Rate
90%Confidence
4Evidence
2023-01-01First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 20 | active | — | — | — |
Root Cause
Node.js or npm scripts fail when project directory contains spaces, commonly in Windows 'My Documents' or 'Program Files'.
genericWorkarounds
-
92% success Move project to a path without spaces or create a junction/symlink
mklink /J C:\project "C:\My Documents\project" # Windows junction; ln -s on Linux
Sources: https://nodejs.org/api/path.html
-
88% success Wrap all path references in double quotes in npm scripts and shell commands
"scripts": { "build": "tsc --project \"./tsconfig.json\"" }
Dead Ends
Common approaches that don't work:
-
Use encodeURIComponent on the path
95% fail
File system APIs expect OS paths, not URI-encoded strings; %20 is treated as literal characters
-
Replace spaces with %20 in package.json scripts
95% fail
Shell and Node resolve %20 as literal text, not as space replacement