Error: ENOSPC: System limit for number of file watchers reached, watch /var/www/html/…
Recently I came across this error when I tried to run my react js app using npm start. To utilize some leisure time and the CORONA VIRUS ( COVID-19) pandemic lock-down period, I thought of learning React JS which is popular among web development community. React was developed by Facebook and is now getting more attentions each day because of its easiness and component based design.
Considering these, I also thought of giving it a try. I created a reactjs project using :
npx create-react-app reactapp
The project was created successfully. I then switched to the app directory :
Then, I ran the app using:
It starts the development server on local device i.e. localhost . It was started successfully on http://127.0.0.1:3000. Since it was supposed to watch file changes and reload page automatically, I made some changes and looked on the browser but there were no any changes and no page reloads. To see the changes, I had to restart the server using npm start again and again.
I looked on the terminal and saw the error message which was something like :
Error: ENOSPC: System limit for number of file watchers reached, watch /var/www/html/...
I thought it was a react-js issue but apparently it was a system issue raised by react-js functionality of watching files. My system is Ubuntu/Linux and I figured out that the limit for file watches is set to a value way smaller than the number of files react watches.
Check current system file watches limit using:
Set MAX WATCHES LIMIT to 524288 using:
echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf
Now, reload system config(sysctl.conf) using:
sudo sysctl -p
You should see the result “fs.inotify.max_user_watches=524288” on the terminal. Now you are all set to run your project. Hit npm start and see if error vanishes.
Let me know if it worked or not. If it did let your colleagues know by sharing this article.