How to Fix the "ENOSPC: System Limit for Number of File Watchers Reached" Error When Running npm run dev

Post Reply
User avatar
isscbta
Team Member
Posts: 146
Joined: Mon Jul 19, 2021 1:41 am
Has thanked: 18 times
Been thanked: 3 times

We encountered an issue when running the command `npm run dev` on our server. Here's a quick overview:

Issue Description:

1. The `npm run dev` command starts normally for a second or two.
2. Then the system begins to output errors: `Error: ENOSPC: System limit for number of file watchers reached, watch`.
3. The command fails to complete successfully.

Steps to Reproduce:
1. In the folder `~/web/dev.jeftinoputovanje.com/jeftput`, run `npm run dev`.
2. After a short period, the error appears, indicating the system limit for file watchers has been reached.

Through investigation, we found that the error is likely related to the default system limit for file watchers. The application requires more watchers than currently available. A potential solution is to increase the number of available file watchers, or to check what else on the server is consuming watchers so you can reduce usage if possible.

For further details, you can refer to the following links:
1. https://laracasts.com/discuss/channels/ ... yId=852603
2. https://stackoverflow.com/questions/557 ... rs-reached

Below are two code blocks demonstrating the output we receive:

**Code block1**:

Code: Select all

VITE v4.5.1 ready in 228 ms

→ Local:  http://localhost:5173/
→ Network: use --host to expose
→ press h to show help

LARAVEL v10.8.0  plugin v0.7.8

→ APP_URL: http://localhost
**Code block2**:

Code: Select all

(node:2008118) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag "--unhandled-rejections=strict" (see https://[MASKED_PATH] for unhandled rejections mode). (rejection id: 20)

(node:2008118) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag "--unhandled-rejections=strict" (see https://[MASKED_PATH] for unhandled rejections mode). (rejection id: 8425)
Solution:
Increase the system limit for file watchers. You can do this by editing the system configuration as follows:

Code: Select all

# insert the new value into the system config
echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p

# check that the new value was applied
cat /proc/sys/fs/inotify/max_user_watches
After applying these changes, re-run

Code: Select all

npm run dev
to see if the issue is resolved. Additionally, consider monitoring overall usage of file watchers on your system and reducing them if possible. This should help prevent reaching the limit again.
Post Reply