Mengatasi Error 'System Limit for Number of File Watchers Reached'

1 menit baca.
Tags: Node.jsShell

Kalau muncul ENOSPC: System limit for number of file watchers reached, limit inotify watcher di Linux terlalu kecil untuk ukuran project kamu.

Ini sering terjadi di Next.js, Vite, Webpack, dan Jest watch mode.

Kenapa error ini muncul

Dev tool memantau banyak file untuk mendeteksi perubahan. Repo besar bisa dengan cepat melewati limit watcher default Linux.

Tanda-tandanya:

  • dev server gagal start
  • hot reload berhenti jalan
  • Jest watch crash

Command fix cepat

Naikkan limit watcher dengan:

echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf
echo fs.inotify.max_user_instances=1024 | sudo tee -a /etc/sysctl.conf
sudo sysctl -p

Lalu restart terminal dan jalankan ulang dev server.

Verifikasi nilainya

Cek limit saat ini:

cat /proc/sys/fs/inotify/max_user_watches
cat /proc/sys/fs/inotify/max_user_instances

Angkanya harus sudah berubah.

Fix sementara (tanpa reboot)

Kalau belum mau edit config:

sudo sysctl fs.inotify.max_user_watches=524288
sudo sysctl fs.inotify.max_user_instances=1024

Nilai ini bisa kembali ke default setelah reboot, jadi config permanen lebih baik.

Catatan WSL

Kalau pakai WSL, jalankan command ini di shell distro WSL, bukan di Windows PowerShell.