Error: ENOSPC: System limit for number of file watchers reached

Note that the development build is not optimized.
To create a production build, use gatsby build

ℹ 「wdm」:
ℹ 「wdm」: Compiled successfully.
error UNHANDLED EXCEPTION


  Error: ENOSPC: System limit for number of file watchers reached, watch '/home/foldername/xxx'

  - watchers.js:165 FSWatcher.start
    internal/fs/watchers.js:165:26

  - nodefs-handler.js:37 createFsWatchInstance
    [abcrypto]/[chokidar]/lib/nodefs-handler.js:37:15

  - nodefs-handler.js:80 setFsWatchListener
    [abcrypto]/[chokidar]/lib/nodefs-handler.js:80:15

Solution

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