The ENFILE error occurs when npm exceeds the operating system's limit for simultaneously open files during package installation. Resolve it by increasing file descriptor limits.
The ENFILE error (file table overflow) is a system-level error that occurs when npm exceeds the operating system's limit for simultaneously open files. This happens because npm attempts to open many files concurrently during package installation and dependency resolution—typically when scanning node_modules directories. The system's file descriptor table, which tracks all open files across all processes, reaches its maximum capacity, preventing npm from opening additional files needed to complete its operations. This is distinct from EMFILE errors—ENFILE indicates system-wide file table overflow (all processes combined), while EMFILE indicates per-process file descriptor limit overflow. Projects with large dependency trees (100+ packages) can easily hit these limits.
First, determine what your current limit is:
ulimit -nOn macOS, the default is typically 256, which is often too low for npm operations. On Linux, the default is usually 1024. If your limit is below 4096, you should increase it.
Before attempting npm install again, increase the limit for your current shell session:
ulimit -n 65536This increases the limit to 65536 for just the current terminal session. After you close the terminal, the limit will revert to the system default.
To persist the change across sessions on Linux, edit the system limits file:
sudo nano /etc/security/limits.confAdd these lines at the end:
* soft nofile 65536
* hard nofile 65536Save and exit, then log out and log back in for changes to take effect. Verify with ulimit -n.
On macOS, use launchctl to increase limits:
sudo launchctl limit maxfiles 65536 unlimitedFor Apple Silicon Macs, you can also run:
sudo sysctl -w kern.maxfiles=10485760
sudo sysctl -w kern.maxfilesperproc=1048576After increasing your file descriptor limit, clean up and retry npm operations:
npm cache clean --force
rm -rf node_modules
rm package-lock.json
npm installIf you're still experiencing issues, try reducing npm's concurrency:
npm install --concurrency 1Close unnecessary applications, especially browsers with many tabs, IDEs, and Docker containers. On macOS/Linux, identify which applications are using the most file descriptors:
lsof -n +c 0 | cut -f1 -d' ' | uniq -c | sort -rn | head -20On Linux, also check the OS-wide file descriptor limit:
cat /proc/sys/fs/file-maxnpm's parallel package resolution algorithm opens files aggressively to speed up installation. On macOS, the default per-process limit of 256 is among the lowest of any OS. In Docker/Lambda environments with hard constraints, using npm with reduced concurrency or installing dependencies in a lower-level image before layering is more reliable than fighting system limits. Some teams install watchman (brew install watchman) on macOS to improve file watching performance and reduce descriptor churn.
npm ERR! code E401 npm ERR! 401 Unauthorized - Token has expired
Token has expired - npm authentication failure
npm ERR! code EAI_NODATA npm ERR! errno EAI_NODATA npm ERR! getaddrinfo EAI_NODATA registry.npmjs.org
How to fix "npm ERR! code EAI_NODATA - getaddrinfo EAI_NODATA"
npm ERR! code EMPTYPACKAGE npm ERR! Package contains no files
How to fix 'npm ERR! code EMPTYPACKAGE' - Package contains no files
npm ERR! code EWORKSPACEMISSING npm ERR! Workspace does not exist: packages/missing
How to fix "npm ERR! code EWORKSPACEMISSING - Workspace does not exist" error
npm ERR! code EADDRNOTAVAIL npm ERR! errno EADDRNOTAVAIL npm ERR! Address not available
How to fix "npm ERR! code EADDRNOTAVAIL - Address not available" error