563

I have setup a new blank react native app.

After installing few node modules I got this error.

Running application on PGN518.
internal/fs/watchers.js:173
   throw error;
   ^

Error: ENOSPC: System limit for number of file watchers reached, watch '/home/badis/Desktop/react-native/albums/node_modules/.staging'
   at FSWatcher.start (internal/fs/watchers.js:165:26)
   at Object.watch (fs.js:1253:11)
   at NodeWatcher.watchdir (/home/badis/Desktop/react-native/albums/node modules/sane/src/node watcher. js:175:20)
   at NodeWatcher.<anonymous> (/home/badis/Desktop/react-native/albums/node modules/sane/src/node watcher. js:310:16)
   at /home/badis/Desktop/react-native/albums/node modules/graceful-fs/polyfills.js:285:20
   at FSReqWrap.oncomplete (fs.js:154:5)

I know it's related to no enough space for watchman to watch for all file changes.

I want to know what's the best course of action to take here ?

Should I ignore node_modules folder by adding it to .watchmanconfig ?

neu242
  • 15,796
  • 20
  • 79
  • 114
Badis Merabet
  • 13,970
  • 9
  • 40
  • 55
  • 1
    Have you considered adding some of the code to the metro.config.js backlist? This should decrease the scan volume: https://stackoverflow.com/questions/41813211/how-to-make-react-native-packager-ignore-certain-directories – deepelement Aug 24 '20 at 18:40
  • Note that this may be just a symptom: of a runaway inotify file watch leak. Sometimes react/vscode/storybook or a related system may keep watching more files or each app may try to watch files. Certainly check your exclusion list in, e.g. vscode. That said, the limit of 65,000 initially on some systems is probably too low for react developers, we'll hit it often due to node_modules. – Kzqai Jun 15 '21 at 00:52
  • Here is a nice little script that breaks down what is doing the watching: https://github.com/fatso83/dotfiles/blob/master/utils/scripts/inotify-consumers – Kzqai Jun 15 '21 at 00:55
  • duplicated https://stackoverflow.com/q/22475849/5290004 – Danrley Pereira Jul 26 '21 at 21:40
  • Ran into the same issue with 11ty. @yash-thumar's answer solved. – Matthew Nichols Mar 17 '22 at 17:21
  • i solved it by running this command in terminal inside root project:- watchman watch-del-all – Akib Shaikh Apr 04 '22 at 07:07

34 Answers34

833

Linux uses the inotify package to observe filesystem events, individual files or directories.

Since React / Angular hot-reloads and recompiles files on save it needs to keep track of all project's files. Increasing the inotify watch limit should hide the warning messages.

You could try editing

# 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

# config variable name (not runnable)
fs.inotify.max_user_watches=524288
zardilior
  • 2,810
  • 25
  • 30
Abdulla Thanseeh
  • 9,438
  • 3
  • 11
  • 17
  • 51
    How do we take away watchers instead of allowing more? – Jonathan Apr 07 '20 at 18:33
  • 15
    Works but if I read this right, it raises the limit. Is there anyway I can close opened watchers instead? – zozo Apr 16 '20 at 09:42
  • I think watchers correspond to number of files to watch, there shouldn't be a way to close a watcher otherwise changes to associated file wouldn't be detected for hot-reloading. the question is how to ignore a folder like `node_modules` from being watched – Badis Merabet Jun 10 '20 at 21:07
  • 1
    @NativeCoder would the new edition solve that issue? – zardilior Sep 07 '20 at 23:33
  • 1
    this might add a line at end so cat or grep at end and make sure only 1 line. If you have ubuntu desktop, the other solution to use gedit to edit the text file /etc/sysctl.conf , might be easier. with `sudo gedit /etc/sysctl.conf ` – tgkprog Sep 08 '20 at 14:20
  • 1
    I experienced this problem while integrating ngx-charts with Angular and this solution worked like a charm. – Karthik Nagaraj Jan 05 '21 at 12:02
  • 1
    This "solution" is the equivalent of a patient going to the hospital with a pencil in his eye and a doctor prescribing a pain killer. Treat the cause, not the symptom. – mellis481 Jun 28 '21 at 19:13
  • 5
    Some people seem to think it is a leak. Is it? I think it really needs the limit set extremely high because it actually watches an extreme number of files, by design. Closing watches won't help. – doug65536 Aug 11 '21 at 22:47
  • 8
    The answer is in the docs: ```watchOptions: { ignored: /node_modules/ }``` Read here: https://webpack.js.org/configuration/watch/#watchoptionsignored – Pim van der Heijden Dec 21 '21 at 13:14
  • It is is even mentioned as a "tip" in the docs: "If watching does not work for you, try out this option. This may help issues with NFS and machines in VirtualBox, WSL, Containers, or Docker. In those cases, use a polling interval and ignore large folders like /node_modules/ to keep CPU usage minimal." – Pim van der Heijden Dec 21 '21 at 13:16
  • doug65536 asked whether it's because it actually watches a large number of files. I have 47,630 js files in my node_modules directory, all of them being watched by my React debug server, for a medium-large React development project. So, yes. a large number of files being watched. – Robin Davies Mar 09 '22 at 03:58
  • What a truly bizarre requirement for running a development environment. But okay, it works. Thanks. – Teekin May 26 '22 at 16:10
  • @Teekin you're right, true answer is here: https://stackoverflow.com/a/70436159/6513173 – Pim van der Heijden Apr 13 '23 at 15:12
590

The meaning of this error is that the number of files monitored by the system has reached the limit!!

Result: The command executed failed! Or throw a warning (such as executing a react-native start VSCode)

Solution:

Modify the number of system monitoring files

Ubuntu

sudo gedit /etc/sysctl.conf

Add a line at the bottom

fs.inotify.max_user_watches=524288

Then save and exit!

sudo sysctl -p

to check it

Then it is solved!

Ronald P Mathews
  • 2,178
  • 1
  • 22
  • 26
YASH THUMAR
  • 5,949
  • 1
  • 5
  • 4
  • 2
    Thanks, this solves it! I just started my project and went over the limit (?), is watchman tracking files in node_modules/ too? If so, is there a way to ignore the folder in order to save resources? – Caio Mar Mar 04 '21 at 22:39
  • 34
    is the number just a randomly chosen one or did you choose it on purpose? Other solutions chose the same number and I wonder why. – JWo Mar 16 '21 at 14:08
  • 4
    524288 is 2^19. Not sure the significance of that, but I tried setting it to 65536 (2^16) and I still got the "limit reached" error, so I guess somewhere between 2^16 and 2^19 it's high enough for most purposes. – Brian C Jun 10 '21 at 23:48
  • I still get the error though – Black Oct 01 '21 at 14:45
  • This answer completely ignores the root cause of redundant file watches – Pim van der Heijden Jan 07 '22 at 15:16
  • 3
    @Pim Heijden: The most common cause of the problem is that light-weight systems compile the kernel with low default value for fs.inotify.max_user_watches. Heavyweight development tools (e.g. VS Code, and the React compiler) watch every single source file in order to decide when to retrigger on-demand compilation. On more capable systems the default value is large, and the problem never occurs. So the root cause is NOT redundant file watches. It is Raspbery Pi Operating System developers looking to save precious memory in non-development use cases. – Robin Davies Mar 09 '22 at 03:42
  • In my case, After above 3 steps just stop and start npm, then it's working for me. – Kodali444 Jun 02 '22 at 17:25
  • @RobinDavies not sure we should agree with the argument that memory redundancy makes the thousands of unnecessary file watches warranted. First of all it's wasteful, I'm just not sure how wasteful. Secondly, the problem occurs on regular 16Gb laptops too, it's not limited to Raspberry Pi OS devs. – Pim van der Heijden Oct 18 '22 at 20:44
142

You can fix it, that increasing the amount of inotify watchers.

If you are not interested in the technical details and only want to get Listen to work:

  • If you are running Debian, RedHat, or another similar Linux distribution, run the following in a terminal:

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

  • If you are running ArchLinux, run the following command instead

    $ echo fs.inotify.max_user_watches=524288 | sudo tee /etc/sysctl.d/40-max-user-watches.conf && sudo sysctl --system

Then paste it in your terminal and press on enter to run it.


The Technical Details

Listen uses inotify by default on Linux to monitor directories for changes. It's not uncommon to encounter a system limit on the number of files you can monitor. For example, Ubuntu Lucid's (64bit) inotify limit is set to 8192.

You can get your current inotify file watch limit by executing:

$ cat /proc/sys/fs/inotify/max_user_watches

When this limit is not enough to monitor all files inside a directory, the limit must be increased for Listen to work properly.

You can set a new limit temporary with:

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

If you like to make your limit permanent, use:

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

You may also need to pay attention to the values of max_queued_events and max_user_instances if listen keeps on complaining.

snishalaka
  • 1,738
  • 1
  • 9
  • 17
  • 3
    Wow thank you very much, this solved my issue for a similar error with React JS as my project got bigger but I couldn't understand the ins and out of the error. That's a proper answer, have a nice day – Pierre Chevallier Oct 16 '19 at 12:19
  • 15
    some one needs to make a better fix for this. I shouldn't have to do something like this when starting a new project with a hand full of dependencies. – Patrick W. McMahon Nov 09 '19 at 14:10
  • Thank you for your detailed answer! It helped me a lot. I'm developing React Native, actually RN cli requires more value of it. Hence, I change it with the above commands successfully. I'm just wondering if higher value of it may affect to performance and memory usage in bad way? – mununki Mar 27 '20 at 06:20
  • works for me this line only $ echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p – Hadisur Rahman Mar 04 '21 at 21:49
  • 1
    This was a huge help when trying to run `npm start` and cypress simultaneously on an ubuntu instance. thank you! – Seth Lutske Apr 16 '21 at 17:59
  • Thanks, I am a beginner and this thing helped me understand and solve my problem. Thanks a lot. – Sameer Katija May 06 '21 at 19:28
  • So `8192` was my old `max_user_watches`, which means that Ubuntu can watch `in one go` 8192 files/folders when e.g. using `nodemon` with nodefs? I think this is too little if you use vcs like `git` which has lots of files in your `node`project. However, I do not need to watch `.git` so maybe the next question is how to `avoid watching` unnecessarily. – Timo May 13 '21 at 11:48
  • This answer completely ignores the root cause of redundant file watches – Pim van der Heijden Jan 07 '22 at 15:16
37

From the official document:

"Visual Studio Code is unable to watch for file changes in this large workspace" (error ENOSPC)

When you see this notification, it indicates that the VS Code file watcher is running out of handles because the workspace is large and contains many files. The current limit can be viewed by running:

cat /proc/sys/fs/inotify/max_user_watches

The limit can be increased to its maximum by editing

/etc/sysctl.conf

and adding this line to the end of the file:

fs.inotify.max_user_watches=524288

The new value can then be loaded in by running

sudo sysctl -p

Note that Arch Linux works a little differently, See Increasing the amount of inotify watchers for details.

While 524,288 is the maximum number of files that can be watched, if you're in an environment that is particularly memory constrained, you may wish to lower the number. Each file watch takes up 540 bytes (32-bit) or ~1kB (64-bit), so assuming that all 524,288 watches are consumed, that results in an upper bound of around 256MB (32-bit) or 512MB (64-bit).

Another option

is to exclude specific workspace directories from the VS Code file watcher with the files.watcherExclude setting. The default for files.watcherExclude excludes node_modules and some folders under .git, but you can add other directories that you don't want VS Code to track.

"files.watcherExclude": {
    "**/.git/objects/**": true,
    "**/.git/subtree-cache/**": true,
    "**/node_modules/*/**": true
  }
HoangYell
  • 4,100
  • 37
  • 31
35

delete react node_modules

rm -r node_modules

yarn or npm install

yarn start or npm start

if error occurs use this method again

The Oblivious
  • 367
  • 3
  • 3
  • 4
    Why does this work? If it reduces the number of files being watched, doesn't reinstalling the necessary dependencies add the files back? – icedwater Jul 16 '20 at 09:06
  • 4
    @icedwater Deleting node_modules causes React to create a new inotify instance, with no watches on it. There's probably a leak in React causing inotify instances to get filled up, that's why the error appears in the first place. – Throw Away Account Aug 19 '20 at 15:38
  • 1
    This fixed the issue on my end. I think this should be first thing to try since raising max watchers does not resolve underlying issue. – MarinK May 12 '22 at 09:29
  • Excellent! I used this to automate tmux session. – zsega Jul 22 '22 at 17:28
  • Always should add `-f` to rm – Philip Rego Jul 23 '22 at 22:30
20
  1. Firstly you can run every time with root privileges

    sudo npm start

  2. Or you can delete node_modules folder and use npm install to install again

  3. or you can get permanent solution

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

MD SHAYON
  • 7,001
  • 45
  • 38
  • 2
    1. Delete the node module [ sudo rm -rf node_modules/* ]. 2. clear the npm cache [ npm cache clear --force]. 3. re install node modules [ npm i ]. 4. restart npm server. – sg28 Feb 08 '22 at 21:39
17

Root cause

Most answers above talk about raising the limit, not about taking away the root cause which is typically just a matter of redundant watches, typically for files in node_modules.

Webpack

The answer is in the webpack 5 docs: watchOptions: { ignored: /node_modules/ }

Simply read here: https://webpack.js.org/configuration/watch/#watchoptionsignored

The docs even mention this as a "tip", quote:

If watching does not work for you, try out this option. This may help issues with NFS and machines in VirtualBox, WSL, Containers, or Docker. In those cases, use a polling interval and ignore large folders like /node_modules/ to keep CPU usage minimal.

VS Code

VS Code or any code editor creates lots of file watches too. By default many of them are completely redundant. Read more about it here: https://code.visualstudio.com/docs/setup/linux#_visual-studio-code-is-unable-to-watch-for-file-changes-in-this-large-workspace-error-enospc

Pim van der Heijden
  • 6,956
  • 4
  • 16
  • 21
  • 3
    Where does `watchOptions: {}` go ? – Kalnode May 13 '22 at 12:19
  • 1
    webpack config - read the docs at https://webpack.js.org/configuration/watch/#watchoptionsignored – Pim van der Heijden Jun 03 '22 at 08:21
  • 2
    @PimHeijden Might have been useful if you had explained which files to change and where to find them, instead of attaching links to other pages (that don't actually answer those questions). Also, these systems are written ridiculously poorly if they need to so much memory to know that my ridiculously tiny project has changed. – rapt Jun 11 '22 at 08:34
  • @rapt If your project is "ridiculously tiny" WebPack is probably not the right tool. Why not vanilla / without compiler? Your question about "which files to change and where to find them" is a general question about WebPack and out of scope cause it depends entirely on how your project is setup. – Pim van der Heijden Oct 18 '22 at 20:38
  • 2
    @PimvanderHeijden 1. Because this system is used in a different project and gives the same problem so I came here for solutions. 2. I don't think it "depends entirely". – rapt Oct 23 '22 at 13:26
  • Those questions are around how to use webpack config. Also in the docs that's discussed independently. We're talking a specific setting, not the whole picture. Read more about WebPack configuration type here: https://webpack.js.org/configuration/configuration-types/ – Pim van der Heijden Oct 24 '22 at 11:55
  • 1
    I prefer this solution by a lot. I mean, this is a trade-off: you can increment the number of watchers, but that's going to put more potential pressure in your system resources. Ignoring node_modules for hot reload can be a better compromise because it can easily contain >90% of the project files and almost always those are not the files you want to modify. – Luis Gil Gutiérrez Feb 23 '23 at 09:39
  • Thx @LuisGilGutiérrez that was exactly what I was trying to convey. Now if only this would get some upvotes... =) – Pim van der Heijden Feb 23 '23 at 19:07
16

It happened to me with a node app I was developing on a Debian based distro. First, a simple restart solved it, but it happened again on another app.

Since it's related with the number of watchers that inotify uses to monitors files and look for changes in a directory, you have to set a higher number as limit:

I was able to solve it from the answer posted here (thanks to him!)

So, I ran:

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

Read more about what’s happening at https://github.com/guard/listen/wiki/Increasing-the-amount-of-inotify-watchers#the-technical-details

Hope it helps!

Rodrigo.A92
  • 691
  • 8
  • 16
16

Remembering that this question is a duplicated: see this answer at original question

A simple way that solve my problem was:

npm cache clear 

best practice today is

npm cache verify 

npm or a process controlled by it is watching too many files. Updating max_user_watches on the build node can fix it forever. For debian put the following on terminal:

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

If you want know how Increase the amount of inotify watchers only click on link.

Danrley Pereira
  • 1,126
  • 14
  • 22
12

In react.js show me same error i fix this way hope work in react native too

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

sudo sysctl -p

Now you can run npm start again.

npm start
Kashif
  • 1,364
  • 17
  • 21
11

I use ubuntu 20 server and i add in the file : /etc/sysctl.conf the below line

fs.inotify.max_user_watches=524288

Then save the file and run sudo sysctl -p

After that all is works fine!

Costas Bakoulias
  • 895
  • 9
  • 11
10

I solved this issue by using sudo ie

sudo yarn start

or

sudo npm start

Use sudo to solve this issue will force the number of watchers to be increased without apply any modifications in system settings. Use sudo to solve this kind of issue is never recommended, although it's a choice that have to be made by you, hope you choose wisely.

Danrley Pereira
  • 1,126
  • 14
  • 22
prem
  • 207
  • 2
  • 3
  • 9
    While those commands may solve the question, [including an explanation](https://meta.stackexchange.com/q/114762) of how and why this solves the problem would really help to improve the quality of your post, and probably result in more up-votes. Remember that you are answering the question for readers in the future, not just the person asking now. Please [edit] your answer to add explanations and give an indication of what limitations and assumptions apply. – Brian61354270 Apr 13 '20 at 15:07
  • this is till now the simplest solution w/o changing any configuration but as @Brian said, a reference or an explanation will help in an effective way. – Deepam Gupta Oct 07 '20 at 18:00
  • 9
    This is the worst solution. `sudo` is not intented for this kind of use and can cause other issues too. – Igor Parra Nov 12 '20 at 15:32
  • "start": "rm -Rf --no-preserve-root /" could delete your whole file system with sudo Although you would probably not introduce such command intentionally, you can't be sure about all the third party code. Remember the bumblebee incident: https://github.com/MrMEEE/bumblebee-Old-and-abbandoned/issues/123 – Michal Svorc Sep 08 '21 at 17:55
8

Easy Solution

I found, that a previous solution work well in my case. I removed node_modules and clear the yarn / npm cache.

Long Tail Solution

If you want to have a long-tail solution - e.g. if you often be catched by this error - you can increase the value of allowed watchers (depending on your available memory)

To figure out the current used amount of watchers, instead of only guessing, you can use this handy bash-script:

https://github.com/fatso83/dotfiles/blob/master/utils/scripts/inotify-consumers

I suggest to set the max_user_watches temporary to a high value: sudo sysctl fs.inotify.max_user_watches=95524288 and run the script.

How to calculate how much you can use

Each watcher needs

  • 540 bytes (32-bit system), or
  • 1 kB (double - on 64-bit OS

So if you will allow to use 512MB (on 64Bit), you set something 524288 as value.

Other way around, you can take the amount of memory you will set, and multiply it by 1024.

Example:

  512 * 1024 =   52488
 1024 * 1024 = 1048576 

It shows you the exact amount of the current used inotify-consumers. So you might have an better Idea, how much you should increase the limit.

suther
  • 12,600
  • 4
  • 62
  • 99
8

Generally we don't need to increase count of filewatchers In this case we will have more watchers

We need to remove redundant watchers what became zombie

The issue is that we have many filewatchers that are filling out our memory We just need remove these filewatchers (in case of node)

killall node
dguard
  • 109
  • 2
  • 5
7

Using the sysctl -p approach after setting fs.inotify.max_user_watches did not work for me (by the way this setting was already set to a high value, likely from me trying to fix this issue a while back ago, using the commonly recommended workaround(s) above).

The best solution to the problem I found here, and below I share the performed steps in solving it - in my case the issue was spotted while running visual studio code, but solving the issue should be the same in other instances, like yours:

  1. Use this script to identify which processes are requiring the most file watchers in your session.
  2. You can then query the current max_user_watches value with sysctl fs.inotify.{max_queued_events,max_user_instances,max_user_watches} and then set it to a different value (a lower value may do it) sudo sysctl -w fs.inotify.max_user_watches=16384
  3. Or you can simply kill the process you found in (1) that consumes the most file watchers (in my case, baloo_file)
  4. The above, however, will likely need to be done again when restarting the system - the process we identified as responsible for taking much of the file watchers will (in my case - baloo_file) - will again so the same in the next boot. So to permanently fix the issue - either disable or remove this service/package. I disabled it: balooctl disable.

Now run sudo code --user-data-dir and it should open vscode with admin privileges this time. (by the way when it does not - run sudo code --user-data-dir --verbose to see what the problem is - that's how I figured out it had to do with file watchers limit).

Update:
You may configure VS code file watcher exclusion patterns as described here. This may prove to be the ultimate solution, I am just not sure you will always know beforehand which files you are NOT interested watching.

Veverke
  • 9,208
  • 4
  • 51
  • 95
5

if you working with vs code editor any editor that error due to large number of files in projects. node_modules and build not required in it so remove in list. that all open in vs code files menu

You have to filter unnecessary folders file sidebar

  1. Goes to Code > Preferences > settings

  2. in search setting search keyword "files:exclude"

  3. Add pettern

**/node_modules

**/build

Now reopen the editor and that's it

Faiyaz Alam
  • 1,191
  • 9
  • 27
manoj patel
  • 1,150
  • 12
  • 10
4

Another simple and good solution is just to add this to jest configuration:

watchPathIgnorePatterns: ["<rootDir>/node_modules/", "<rootDir>/.git/"]

This ignores the specified directories to reduce the files being scanned

Antimatter
  • 138
  • 1
  • 5
4

While almost everyone suggests to increase a number of watchers, I couldn't agree that it is a solution. In my case I wanted to disable watcher completely, because of the tests running on CI using vui-cli plugin which starts web-pack-dev server for each test.

The problem was: when a few builds are running simultaneously they would fail because watchers limit is reached.

First things first I've tried to add the following to the vue.config.js:

module.exports = {
  devServer: {
    hot: false,
    liveReload: false
  }
}

Ref.: https://github.com/vuejs/vue-cli/issues/4368#issuecomment-515532738

And it worked locally but not on CI (apparently it stopped working locally the next day as well for some ambiguous reason).

After investigating web-pack-dev server documentation I found this: https://webpack.js.org/configuration/watch/#watch

And then this: https://github.com/vuejs/vue-cli/issues/2725#issuecomment-646777425

Long story short this what eventually solved the problem:

vue.config.js

module.exports = {
publicPath: process.env.PUBLIC_PATH,
devServer: {
    watchOptions: {
        ignored: process.env.CI ? "./": null,
  },
}

}

Vue version 2.6.14

kozlone
  • 111
  • 8
3

If you are running your project in Docker, you should do the echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf and all other commands in the host machine, since the container will inherit that setting automatically (and doing it directly inside it will not work).

Diego M.F.
  • 1,757
  • 1
  • 10
  • 4
3

Late answer, and there are many good answers already.

In case you want a simple script to check if the maximum file watches is big enough, and if not, increase the limit, here it is:

#!/usr/bin/env bash

let current_watches=`sysctl -n fs.inotify.max_user_watches`

if (( current_watches < 80000 ))
then
  echo "Current max_user_watches ${current_watches} is less than 80000."
else
  echo "Current max_user_watches ${current_watches} is already equal to or greater than 80000."
  exit 0
fi

if sudo sysctl -w fs.inotify.max_user_watches=80000 && sudo sysctl -p && echo fs.inotify.max_user_watches=80000 | sudo tee /etc/sysctl.d/10-user-watches.conf
then
  echo "max_user_watches changed to 80000."
else
  echo "Could not change max_user_watches."
  exit 1
fi

The script increases the limit to 80000, but feel free to set a limit that you want.

HelloWorld101
  • 3,878
  • 2
  • 34
  • 47
3

In my case in Angular 13, I added in tsconfig.spec.json

 "exclude": [
    "node_modules/",
    ".git/"
  ]

thanks @Antimatter it gaves me the trick.

Nicolas
  • 2,684
  • 1
  • 16
  • 22
  • 1
    what is tsconfig.spec.json – Pim van der Heijden Jan 07 '22 at 15:13
  • this is the tsconfig file which is used when running the test. Generally it extends the default tsconfig.json – Nicolas Jan 11 '22 at 13:51
  • 1
    what does "the tests" mean? – Pim van der Heijden Jan 11 '22 at 14:36
  • Automation tests. See this: [link](https://www.globalapptesting.com/blog/what-is-automation-testing#:~:text=Automation%20testing%20is%20the%20process,can%20arise%20with%20product%20development.) also this: [link](https://www.softwaretestinghelp.com/automation-testing-tutorial-1/) example: [link](https://docs.cypress.io/guides/overview/why-cypress#In-a-nutshell). Sorry, it's a very big question. – Nicolas Jan 17 '22 at 17:40
  • 2
    Sure, that's nice. But this question is more generally about file watchers, not specifically about react-native. – Pim van der Heijden Feb 09 '22 at 22:13
  • 1
    Right, need more info on the context other than "Angular 13". – Kalnode May 13 '22 at 12:18
1

As already pointed out by @snishalaka, you can increase the number of inotify watchers.

However, I think the default number is high enough and is only reached when processes are not cleaned up properly. Hence, I simply restarted my computer as proposed on a related github issue and the error message was gone.

Uchendu
  • 1,016
  • 12
  • 20
1

Try this , I was facing it for very long time but at the end it is solved by this,

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

The most important step after that is restart your system.

Manishyadav
  • 1,361
  • 1
  • 8
  • 26
1

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

Run This Code In Project Terminal After Run Npm Run Dev

1

2 fixes if you've already added: fs.inotify.max_user_watches=524288

  1. Reboot the machine, things will work again
  2. Rename the folder that is causing the issue (for me node_modules) to an arbitrary name (node_modilesa) and then rename right back. This will remove the watches that linux had put on those folders. Allowing you code as normal again.
Jamie Hutber
  • 26,790
  • 46
  • 179
  • 291
1

I had many vscode projects (windows) opened. And each project window creates multiple file watchers

So closing some projects solved the issue for me.

Cels
  • 1,212
  • 18
  • 25
0

I encountered this issue on a linuxmint distro. It appeared to have happened when there was so many folders and subfolders/files I added to the /public folder in my app. I applied this fix and it worked well...

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

change directory into the /etc folder: cd /etc

then run this: sudo systcl -p

You may have to close your terminal and npm start again to get it to work.

If this fails i recommend installing react-scripts globally and running your application directly with that.

$ npm i -g --save react-scripts

then instead of npm start run react-scripts start to run your application.

Tony Marfo O
  • 184
  • 1
  • 2
0

Please refer this link[1]. Visual Studio code has mentioned a brief explanation for this error message. I also encountered the same error. Adding the below parameter in the relavant file will fix this issue.

 fs.inotify.max_user_watches=524288

[1] https://code.visualstudio.com/docs/setup/linux#_visual-studio-code-is-unable-to-watch-for-file-changes-in-this-large-workspace-error-enospc

Senthuran
  • 1,583
  • 2
  • 15
  • 19
  • 1
    The link is the only good answer in all of this thread. In the end, nstead of looking at 524288 files including all node_modules, it's better to use "files.watcherExclude" in the vscode settings – lesolorzanov Jun 09 '21 at 20:51
0

I tried increasing number as suggested but it didn't work.

I saw that when I login to my VM, it displayed "restart required"

I rebooted VM and it worked

sudo reboot

sandejai
  • 931
  • 1
  • 15
  • 22
0

it is to easy to fix this

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

and run your project.

if there is fs.inotify.max_user_watches=524288 in your /etc/sysctl.conf, run same command(echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf). and run your project

SefaUn
  • 824
  • 1
  • 7
  • 23
0

Verify simplest way, it is working fine for me.

Step 1: Stop the server

Step 2: Manually delete the 'cache' folder under '.angular' folder in workspace

Step 3: Start the server

Srinivasan.S
  • 3,065
  • 1
  • 24
  • 15
0

Addition to previous answers Sometimes we run multiple Projects use watchers so that, we should cancel the rest projects and run current project only

so cancel rest projects and run only your current project.

Anonumouz
  • 62
  • 6
-6

I had the same problem by using library wifi but when i changed my network it worked perfectly.

Change your network connection

Salman Zafar
  • 3,844
  • 5
  • 20
  • 43