Error: ENOSPC: System limit for number of file watchers reachedへの対処方法


環境
OS:Ubuntu18.04
Node.js:12.16.1
npm:6.13.4

Linuxで監視できるファイル数の制限を超えると発生するエラー

監視ファイル数を確認する

$ cat /proc/sys/fs/inotify/max_user_watches
=> 8192

一時的に制限を設定する場合

$ sudo sysctl fs.inotify.max_user_watches = 524288
$ sudo sysctl -p

永続的に制限を設定する場合

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

$ sudo sysctl -p
=> fs.inotify.max_user_watches = 524288

参考
https://github.com/guard/listen/wiki/Increasing-the-amount-of-inotify-watchers#the-technical-details