AI Diagnostic Summary

npm ERR! code EMFILE

Well-Documented Error

This error matches known, documented patterns with reliable solutions.

Quick Fix (Most Common Solution)

Seeing "npm ERR! code EMFILE"? This error can be frustrating, but it's usually fixable. It typically affects your development workflow or system. Below you'll find clear, step-by-step solutions to resolve this issue.

High confidence
What This Error Means

npm opened too many files at once.

Frequently documented in developer and vendor support forums.

Based on documented solutions and common real-world fixes.
Not affiliated with browser, OS, or device manufacturers.

New here? Learn why exact error messages matter →

Common Causes
  • Low system limit
  • Large project
  • Many dependencies
How to Fix
  1. Increase ulimit on Unix
  2. Close other applications
  3. Restart system

Last reviewed: March 2026 How we review solutions

Why This Happens

EMFILE stands for "Error Max FILES" and occurs when npm tries to open a file but the operating system has reached its per-process limit for open file descriptors. Every file, socket, and pipe that a process opens consumes a file descriptor, and the OS enforces a ceiling to prevent a single process from exhausting system resources. On macOS, the default soft limit is notoriously low at 256 open files, while Linux typically allows 1024. Modern npm projects with hundreds or thousands of packages in node_modules easily exceed these limits during installation, as npm opens many package.json files, tarballs, and temporary files simultaneously. The error is particularly common during npm install on large projects, especially the first install where everything must be extracted from cached tarballs. Development tools that watch file systems (Webpack dev server, Vite, Jest in watch mode, nodemon) also consume file descriptors for every watched file, and running these alongside npm install compounds the problem. The fix is straightforward: increase the file descriptor limit using ulimit (temporary) or by editing system configuration files (permanent).

Quick Diagnostic Checklist
  1. Check the current limit: ulimit -n
  2. Temporarily increase: ulimit -n 65536 (in the current shell)
  3. Close other applications that may have many files open
  4. On macOS, check the system limit: launchctl limit maxfiles
  5. If using a file watcher, exclude node_modules from watching
Fixing EMFILE by increasing file descriptor limits
# Error output:
# npm ERR! code EMFILE
# npm ERR! syscall open
# npm ERR! path /home/user/project/node_modules/lodash/package.json
# npm ERR! errno -24
# npm ERR! EMFILE: too many open files, open '/home/user/project/node_modules/lodash/package.json'

# Step 1: Check current limit
$ ulimit -n
256               # <-- Too low for large projects

# Step 2: Increase for current shell session
$ ulimit -n 65536
$ npm install     # Should work now

# Step 3: Make permanent on macOS
$ sudo launchctl limit maxfiles 65536 200000
# Add to /etc/sysctl.conf or create /Library/LaunchDaemons/limit.maxfiles.plist

# Step 3: Make permanent on Linux
$ echo "* soft nofile 65536" | sudo tee -a /etc/security/limits.conf
$ echo "* hard nofile 65536" | sudo tee -a /etc/security/limits.conf
# Log out and back in for changes to take effect

# Step 4: Alternative — use graceful-fs (if you control the code)
# npm install graceful-fs
# const fs = require('graceful-fs');  // Queues file operations
Edge Cases & Unusual Scenarios

Docker container with low default limits

Docker containers inherit file descriptor limits from the host or use their own defaults. Alpine-based containers often have a limit of 1024. Add --ulimit nofile=65536:65536 to your docker run command or set it in docker-compose.yml.

macOS Catalina and later reset limits on reboot

macOS resets ulimit values on each reboot despite edits to .bashrc or .zshrc. You need a LaunchDaemon plist to persist the change. Create /Library/LaunchDaemons/limit.maxfiles.plist with the desired limit.

File watcher leak in development

Tools like Webpack, Vite, and nodemon keep file descriptors open for every watched file. If you restart the dev server repeatedly without closing the old process, orphaned watchers accumulate. Kill stale Node processes: pkill -f node before restarting.

Optional follow-up

Some users ask whether saving fixes for recurring errors would be useful when the same issue appears again.

Was this explanation helpful?

Explanations are based on documented fixes, real-world reports, and common system behavior. GetErrorHelp is independent and not affiliated with software vendors, device manufacturers, or service providers.
Frequently Asked Questions

How to increase limit?

Run ulimit -n 65535 before npm install.

Is this a Windows issue?

More common on Unix systems.

What is a file descriptor?

A file descriptor is a handle the operating system assigns to every open file, network socket, or pipe. Each process has a limited number of these handles. When the limit is reached, any new open() call fails with EMFILE.

Why does macOS have such a low default limit?

macOS defaults to 256 open files per process for historical compatibility. This was sufficient for most applications decades ago but is far too low for modern Node.js development. Increasing it to 65536 has no negative side effects.

Does npm have a built-in way to handle EMFILE?

npm uses the graceful-fs library internally, which queues file operations when the limit is reached. However, extremely low limits (256) can still overwhelm the queue. Increasing the OS limit is the reliable fix.

Related Resources

Also Known As

Common Search Variations

Related Errors
Still Stuck?

Paste a different error message or upload a screenshot to get help instantly.

Solutions are based on commonly documented fixes and may not apply in all situations.