Intro

I have come across a file watchers error a couple of times now with new installs of 11ty and I am documenting the fix in this post for future me.

The Error

When starting a local 11ty dev server with the command:

cmd
npx @11ty/eleventy --serve

You get the following error:

error
Unhandled rejection in promise ([object Promise]): (more in DEBUG output)
^C> ENOSPC: System limit for number of file watchers reached, watch 'network/vendors/juniper/trace-options.njk'


`Error` was thrown:
    Error: ENOSPC: System limit for number of file watchers reached, watch 'network/vendors/juniper/trace-options.njk'
        at FSWatcher. (node:internal/fs/watchers:218:26)
        at Object.watch (node:fs:1550:34)
        at createFsWatchInstance (/home/bradmin/code/js/codingpackets.com-11ty/node_modules/chokidar/lib/nodefs-handler.js:119:15)
        at setFsWatchListener (/home/bradmin/code/js/codingpackets.com-11ty/node_modules/chokidar/lib/nodefs-handler.js:166:15)

        at NodeFsHandler._watchWithNodeFs (/home/bradmin/code/js/codingpackets.com-11ty/node_modules/chokidar/lib/nodefs-handler.js:331:14)
        at NodeFsHandler._handleFile (/home/bradmin/code/js/codingpackets.com-11ty/node_modules/chokidar/lib/nodefs-handler.js:395:23)
        at NodeFsHandler._addToNodeFs (/home/bradmin/code/js/codingpackets.com-11ty/node_modules/chokidar/lib/nodefs-handler.js:628:21)
Unhandled rejection in promise ([object Promise]): (more in DEBUG output)

The Solution

Some quick duck hunting lead me to a github issue for the gatsby project that looked very similar to my issue.

The proposed solution involves upping the max_user_watches setting in the /etc/sysctl.conf file.

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

If you are interested in the gory details then there is a nice and helpful article that explains the issue in detail here.

Long story short. I applied the fix and it works!!! I can now serve my static site without errors.

# 11ty
# node