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

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

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的确切数量。所以你可能有更好的想法,你应该增加多少限制。

其他回答

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

运行Npm后,在项目终端运行此代码

如果你使用vs代码编辑器,由于项目中有大量文件,任何编辑器都会出现错误。Node_modules和build不需要,所以在列表中删除。所有打开在vs代码文件菜单

你必须过滤不必要的文件夹文件侧边栏

进入代码>首选项>设置 在搜索设置中搜索关键字“文件:排除” 添加pettern

* * / node_modules

* * /构建

就是这样

Linux使用inotify包来观察文件系统事件、单个文件或目录。

由于React / Angular会在保存时热加载和重新编译文件,所以它需要跟踪所有项目的文件。增加inotify监视限制应该会隐藏警告消息。

你可以试着编辑

# 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

删除react node_modules

rm -r node_modules

yarn or npm install

yarn start or npm start

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

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

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