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

Also available as: JSON · Markdown
88%Fix Rate
90%Confidence
4Evidence
2023-01-01First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
20 active — — —

Root Cause

Node.js or npm scripts fail when project directory contains spaces, commonly in Windows 'My Documents' or 'Program Files'.

generic

Workarounds

  1. 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

  2. 88% success Wrap all path references in double quotes in npm scripts and shell commands
    "scripts": { "build": "tsc --project \"./tsconfig.json\"" }

    Sources: https://docs.npmjs.com/cli/v10/using-npm/scripts

Dead Ends

Common approaches that don't work:

  1. Use encodeURIComponent on the path 95% fail

    File system APIs expect OS paths, not URI-encoded strings; %20 is treated as literal characters

  2. Replace spaces with %20 in package.json scripts 95% fail

    Shell and Node resolve %20 as literal text, not as space replacement