How to fix npm ERR! code ENAMETOOLONG npm ERR! ENAMETOOLONG: name too long, open 'C:\very\long\path...' in npm
The ENAMETOOLONG error occurs when npm attempts to create or access a file path that exceeds Windows' 260-character MAX_PATH limit. This is caused by deeply nested node_modules directories.
Quick fix
Fixes npm ERR! code ENAMETOOLONG npm ERR! ENAMETOOLONG: name too long, open 'C:\very\long\path...'
npm --version
node --version- Check your current npm and Node.js versions
- Clean install by deleting node_modules and package-lock.json
- Move your project to a shorter path location
- Enable Windows 10/11 long paths support via Registry
npm --versionnode --versionnpm ERR! code ENAMETOOLONGnpm ERR! ENAMETOOLONG: name too long, open 'C:\very\long\path...'
What this error means
The ENAMETOOLONG error occurs when npm (or Node.js) attempts to create or access a file path that exceeds the operating system's maximum path length limit. On Windows, the legacy MAX_PATH limitation restricts file paths to 260 characters, and npm's deeply nested node_modules directory structure can quickly exceed this threshold. When a dependency has its own dependencies, those get installed in a nested node_modules folder (e.g., project/node_modules/package-a/node_modules/package-b/), and this nesting can repeat many levels deep, creating paths that violate Windows' character limit. This is a Windows-specific issue because the Windows API enforces the 260-character MAX_PATH limit on legacy systems and applications, whereas macOS and Linux have much higher path length limits (typically 4,096 characters).
Typical symptoms
- npm install fails with error message: 'ENAMETOOLONG: name too long, open C:\very\long\path...'
- Package installation completes but application fails to load modules from deeply nested node_modules folders
- Error occurs sporadically or only with specific packages that have many sub-dependencies
- CI/CD pipelines fail on Windows machines but succeed on macOS or Linux environments
- Tools like webpack, tsc, or ESLint cannot find packages despite npm install appearing successful
Common causes
- Default project locations like C:\Users\username\Documents\Visual Studio Projects\YourProject consume significant path length before npm adds any dependencies
- Older npm versions (pre-v3) created deeply nested node_modules structures with packages containing their own node_modules folders multiple levels deep
- Packages with long names, scoped packages (@organization/package-name), or multiple versions of the same package in different dependency branches
- Windows 10 versions prior to 1607 or Windows 11 Home editions do not support the LongPathsEnabled registry setting by default
- Some projects use package managers that create even longer flattened paths due to their internal linking structure
How to fix "npm ERR! code ENAMETOOLONG npm ERR! ENAMETOOLONG: name too long, open 'C:\very\long\path...'"
Verify you're running npm v3 or later, which uses a flatter dependency structure:
npm --version
node --versionIf you're on npm v2, upgrade immediately:
npm install -g npm@latestnpm 3+ hoists dependencies to the top-level node_modules whenever possible, preventing deep nesting.
Remove your current node_modules directory and lock file, then perform a fresh installation:
rmdir /s /q node_modules
del package-lock.json
npm installOn PowerShell:
Remove-Item -Recurse -Force node_modules
Remove-Item package-lock.json
npm installThis forces npm to re-evaluate all dependencies and apply the latest flattening strategy.
Windows' 260-character limit includes your entire project path. Move your project closer to the drive root:
Before (problematic):
C:\Users\YourUsername\Documents\Visual Studio Projects\MyCompany\RepositoryName\ProjectFolder\YourApp(This already uses ~80 characters before any dependencies)
After (optimized):
C:\dev\my-appmkdir C:\dev
cd C:\dev
git clone <your-repo>
npm installThis simple change can free up 50-100 characters for your node_modules folder.
Windows 10 (version 1607+) and Windows 11 support file paths longer than 260 characters. Enable this system-wide by running PowerShell as Administrator:
New-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\FileSystem" -Name "LongPathsEnabled" -Value 1 -PropertyType DWORD -ForceOr use the legacy command prompt:
reg add "HKLM\SYSTEM\CurrentControlSet\Control\FileSystem" /v LongPathsEnabled /t REG_DWORD /d 1 /fRestart your computer for the change to take full effect.
If you're on Windows Pro, Enterprise, or Server editions, use Group Policy:
1. Press Win + R, type gpedit.msc, and press Enter
2. Navigate to: Computer Configuration > Administrative Templates > System > Filesystem
3. Find and double-click "Enable Win32 long paths"
4. Select "Enabled" and click "OK"
5. Restart your computer
This provides the same result as the registry edit but through the Group Policy interface.
npm's dedupe command can further reduce path depth by removing duplicate dependencies:
npm dedupeThis scans your node_modules tree and hoists duplicated packages to the highest level where they're used.
For more aggressive flattening, combine with a clean install:
npm ci --prefer-offline
npm dedupeAdvanced notes
Even with Windows long paths enabled, Node.js and some dependent tools may still encounter issues with extremely long paths due to legacy code paths or incomplete manifest configurations. The npm documentation recommends keeping project paths under 100 characters when possible as a safety margin.
If you use alternative package managers, note that pnpm creates symlink-based node_modules structures that may have different path characteristics. Yarn v2+ (Berry) uses the .pnp.js approach which bypasses the node_modules directory entirely, completely avoiding path length issues.
For CI/CD environments (GitHub Actions, Azure Pipelines, Jenkins on Windows), enabling long paths on the build agent's registry is essential.
The 260-character MAX_PATH limit is a Windows API legacy artifact from the original FAT32 file system. The NTFS file system itself supports paths up to 32,767 characters, but Windows API functions traditionally truncated this to maintain backward compatibility.
Frequently asked questions
- What does "npm ERR! code ENAMETOOLONG npm ERR! ENAMETOOLONG: name too long, open" mean?
- js) attempts to create or access a file path that exceeds the operating system's maximum path length limit. On Windows, the legacy MAX_PATH limitation restricts file paths to 260 characters, and npm's deeply nested node_modules directory structure can quickly exceed this threshold. , project/node_modules/package-a/node_modules/package-b/), and this nesting can repeat many levels deep, creating paths that violate Windows' character limit.
- How do I fix "npm ERR! code ENAMETOOLONG npm ERR! ENAMETOOLONG: name too long, open"?
- The ENAMETOOLONG error occurs when npm attempts to create or access a file path that exceeds Windows' 260-character MAX_PATH limit. This is caused by deeply nested node_modules directories.
- What causes "npm ERR! code ENAMETOOLONG npm ERR! ENAMETOOLONG: name too long, open"?
- Default project locations like C:\Users\username\Documents\Visual Studio Projects\YourProject consume significant path length before npm adds any dependencies Older npm versions (pre-v3) created deeply nested node_modules structures with packages containing their own node_modules folders multiple levels deep Packages with long names, scoped packages (@organization/package-name), or multiple versions of the same package in different dependency branches
- Is the "npm ERR! code ENAMETOOLONG npm ERR! ENAMETOOLONG: name too long, open" error serious?
- It is a medium-severity error โ more of a blocker than a risk. The steps above resolve it.
Official resources & further reading
- ๐npm Official Documentation
- ๐npm docs: Windows path issues(Official Docs)
- ๐GitHub: npm Windows path issues(GitHub)
- ๐ฌStack Overflow: ENAMETOOLONG Windows npm(Stack Overflow)