我已经设置了一个新的空白反应本机应用程序。

在安装了几个节点模块后,我得到了这个错误。

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)

我知道这与没有足够的空间让守望者监视所有文件更改有关。

我想知道在这里采取的最佳行动是什么?

我应该忽略node_modules文件夹添加到.watchmanconfig ?


当前回答

简单的解决方案

我发现,之前的解决方案在我的情况下很有效。我删除了node_modules并清除了yarn / npm缓存。

长尾解决方案

如果你想要一个长尾解决方案——例如,如果你经常被这个错误捕获——你可以增加允许的观察者的值(取决于你的可用内存)

要计算出当前使用的观察者数量,而不是仅仅猜测,你可以使用这个方便的bash脚本:

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

我建议将max_user_watches临时设置为一个高值: Sudo sysctl fs.inotify。Max_user_watches =95524288并运行脚本。

如何计算你可以用多少

每个观众都需要

540字节(32位系统),或 1kb(双开64位操作系统

因此,如果您允许使用512MB(在64Bit上),您将设置524288作为值。

反之,您可以将将要设置的内存量乘以1024。

例子:

  512 * 1024 =   52488
 1024 * 1024 = 1048576 

它显示了当前使用的inotify-consumers的确切数量。所以你可能有更好的想法,你应该增加多少限制。

其他回答

删除react node_modules

rm -r node_modules

yarn or npm install

yarn start or npm start

如果发生错误,请再次使用此方法

迟回答,已经有很多好的答案了。

如果你想要一个简单的脚本来检查最大文件监视是否足够大,如果不够大,就增加限制,下面是:

#!/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

脚本将限制增加到80000,但是可以随意设置您想要的限制。

要解决这个问题并不容易

fs.inotify回响。Max_user_watches =524288 | sudo tee -a /etc/sysctl.conf . a

然后运行你的项目。

如果有fs.inotify。在/etc/sysctl.conf文件中,Max_user_watches =524288, 执行相同的命令(echo fs.inotify。Max_user_watches =524288 | sudo tee -a /etc/sysctl.conf)。运行你的项目

我在使用图书馆wifi时也遇到了同样的问题,但当我换了网络后,它工作得很好。

更改网络连接

正如@snishalaka已经指出的,你可以增加inotify观察者的数量。

但是,我认为默认值已经足够高了,只有在没有正确清理进程时才会达到这个值。因此,我只是重新启动了我的电脑,就像在相关的github问题上提出的那样,错误消息消失了。