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.
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).
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 dedupeEven 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.
npm ERR! code ENOAUDIT npm ERR! Audit endpoint not supported
How to fix "npm ERR! code ENOAUDIT - Audit endpoint not supported"
npm ERR! code EBADDEVENGINES npm ERR! devEngines.runtime incompatible with current node version
How to fix "npm ERR! code EBADDEVENGINES - devEngines.runtime incompatible with current node version"
npm ERR! code ETOOMANYARGS npm ERR! Too many arguments
How to fix "npm ERR! code ETOOMANYARGS - Too many arguments"
npm ERR! code EINVALIDTAGNAME npm ERR! Invalid tag name: tag names cannot contain spaces
How to fix "npm ERR! code EINVALIDTAGNAME - tag names cannot contain spaces"
npm ERR! code E400 npm ERR! 400 Bad Request
How to fix "npm ERR! code E400 - 400 Bad Request" error