Are you seeing Error: EMFILE: too many open files
when you start your web app with npm run dev
in VS Code on Linux? This common issue happens because the default file-descriptor limit is too low for modern build tools like Vite, Webpack, or Rollup. In this guide you’ll learn:
- Why the EMFILE error occurs
- How to temporarily raise your
ulimit
- How to make the change permanent
- Additional tips for Vite and VS Code users
What Causes “EMFILE: too many open files”?
The Linux kernel restricts how many files a single process can open simultaneously. Build tools that watch many source files will quickly hit that limit, leading to:
Error: EMFILE: too many open files
On VS Code’s integrated terminal, you may not notice until you start npm run dev
. Vite’s file-watcher can require hundreds or thousands of file descriptors.
Temporary Fix: Increase File Descriptors with ulimit
To quickly raise your soft limit for the current session:
ulimit -Sn 10000
npm run dev
This sets your soft limit to 10,000. Adjust the number as needed based on your project’s file-watch requirements.
Make the Change Permanent
To avoid resetting ulimit
every session, update your system limits:
- Edit
/etc/security/limits.conf
(requires sudo):
sudo nano /etc/security/limits.conf
- Add at the end:
# Increase file descriptors for all users
* soft nofile 10000
* hard nofile 30000
- Save and logout/login, or reboot.
- Verify with:
ulimit -Sn # soft limit
ulimit -Hn # hard limit
Vite Troubleshooting Tips
If increasing ulimit
doesn’t resolve stalls or frozen hot-reload, try:
- Clearing Vite cache:
npm run dev -- --force
- Upgrading to the latest Vite version
- Reviewing the Vite Troubleshooting Guide
Frequently Asked Questions (FAQ)
What is the difference between soft and hard limits?
Soft limits can be raised by any user process up to the hard limit. Hard limits act as an absolute ceiling and can only be raised by root.
Does this affect Docker containers?
Yes. In Docker, set --ulimit nofile=10000:30000
in your run command or Compose file.
Wrap Up
By increasing your file-descriptor limits with ulimit
—temporarily or permanently—you’ll eliminate the EMFILE error when running npm run dev
. Combine this with Vite’s own troubleshooting tips to keep development smooth. If this helped, share this post, leave a comment below, or explore more tips on Linux, JavaScript, and Web Development.