How to fix npm ERR! code ENFILE npm ERR! ENFILE: file table overflow in npm

npmINTERMEDIATEHIGHUpdated Dec 5, 2025· 170 views

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.

Quick fix

Fixes ENFILE

ulimit -n
  1. Check your current file descriptor limit
  2. Increase the file descriptor limit temporarily
  3. Make the file descriptor limit permanent (Linux)
  4. Make the file descriptor limit permanent (macOS)
npm — error
ulimit -n
npm ERR! code ENFILE
npm ERR! ENFILE: file table overflow

What this error means

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.

Typical symptoms

  • npm install or npm ci command fails during dependency resolution or node_modules scanning
  • Error message includes 'syscall scandir' pointing to paths within node_modules
  • Random npm operations fail intermittently, especially when installing large dependency trees
  • System-wide file operations slow down or become unresponsive during npm operations
  • Error disappears temporarily after restarting your machine or closing other applications

Common causes

  1. System file descriptor limit is too low (default on macOS is only 256 per process)
  2. npm is attempting too many concurrent file operations during large package installations
  3. Other applications on your system are consuming many file descriptors (browsers, IDEs, editors, Docker)
  4. Large monorepo projects or packages with thousands of nested dependencies exceed file limits
  5. File handles from previous failed npm operations are not properly closed and accumulate
  6. Docker containers or development environments have restrictive resource limits

How to fix "npm ERR! code ENFILE npm ERR! ENFILE: file table overflow"

1Check your current file descriptor limit

First, determine what your current limit is:

bash
ulimit -n

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

2Increase the file descriptor limit temporarily

Before attempting npm install again, increase the limit for your current shell session:

bash
ulimit -n 65536

This increases the limit to 65536 for just the current terminal session. After you close the terminal, the limit will revert to the system default.

3Make the file descriptor limit permanent (Linux)

To persist the change across sessions on Linux, edit the system limits file:

bash
sudo nano /etc/security/limits.conf

Add these lines at the end:

bash
* soft nofile 65536
* hard nofile 65536

Save and exit, then log out and log back in for changes to take effect. Verify with ulimit -n.

4Make the file descriptor limit permanent (macOS)

On macOS, use launchctl to increase limits:

bash
sudo launchctl limit maxfiles 65536 unlimited

For Apple Silicon Macs, you can also run:

bash
sudo sysctl -w kern.maxfiles=10485760
sudo sysctl -w kern.maxfilesperproc=1048576
5Clean npm cache and reinstall dependencies

After increasing your file descriptor limit, clean up and retry npm operations:

bash
npm cache clean --force
rm -rf node_modules
rm package-lock.json
npm install

If you're still experiencing issues, try reducing npm's concurrency:

bash
npm install --concurrency 1
6Reduce system load and check for file descriptor usage

Close unnecessary applications, especially browsers with many tabs, IDEs, and Docker containers. On macOS/Linux, identify which applications are using the most file descriptors:

bash
lsof -n +c 0 | cut -f1 -d' ' | uniq -c | sort -rn | head -20

On Linux, also check the OS-wide file descriptor limit:

bash
cat /proc/sys/fs/file-max

Advanced notes

npm'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.

Frequently asked questions

What does "ENFILE" mean?
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.
How do I fix "ENFILE"?
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.
What causes "ENFILE"?
System file descriptor limit is too low (default on macOS is only 256 per process) npm is attempting too many concurrent file operations during large package installations Other applications on your system are consuming many file descriptors (browsers, IDEs, editors, Docker)
Is the "ENFILE" error serious?
Yes. This is a high-severity error that usually blocks work until it is fixed, but the steps above resolve it.

Official resources & further reading