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

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

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 ?


当前回答

我在基于Debian的发行版上开发一个节点应用程序时就遇到了这种情况。首先,一个简单的重启就解决了问题,但在另一个应用程序上又发生了这种情况。

因为它与inotify用来监视文件和查找目录更改的监视器数量有关,所以你必须设置一个更高的数字作为limit:

我可以从这里发布的答案中解决它 (感谢他!)

所以,我跑了:

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

详情请登录https://github.com/guard/listen/wiki/Increasing-the-amount-of-inotify-watchers#the-technical-details

希望能有所帮助!

其他回答

记住这个问题是重复的:见原问题的答案

解决我问题的一个简单方法是:

npm cache clear 

今天的最佳实践是

npm cache verify 

NPM或者由它控制的进程正在监视太多的文件。更新构建节点上的max_user_watches可以永远修复它。对于debian,在终端上放以下命令:

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

如果你想知道如何增加inotify观察者的数量,只需要点击链接。

简单的解决方案

我发现,之前的解决方案在我的情况下很有效。我删除了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. conf后,使用sysctl -p方式。Max_user_watches对我来说不起作用(顺便说一下,这个设置已经设置为一个很高的值,可能是我在不久前尝试修复这个问题时使用的,使用上面通常推荐的解决方法)。

我在这里发现的问题的最佳解决方案,下面我分享了解决它的执行步骤-在我的情况下,问题是在运行visual studio代码时发现的,但在其他情况下解决问题应该是一样的,比如你的:

Use this script to identify which processes are requiring the most file watchers in your session. 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 Or you can simply kill the process you found in (1) that consumes the most file watchers (in my case, baloo_file) 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.

现在运行sudo code——user-data-dir,这次它应该以管理员权限打开vscode。(顺便说一下,当它不运行sudo代码——user-data-dir——verbose来查看问题是什么——这就是我如何计算出它与文件观察者限制有关)。

更新: 你可以像这里描述的那样配置VS代码文件监视排除模式。这可能是最终的解决方案,我只是不确定你总是事先知道哪些文件你不感兴趣看。

通常我们不需要增加文件监视器的数量 在这种情况下,我们将有更多的观察员

我们需要移除多余的监视人员

问题是我们有许多文件监视器正在填充我们的内存 我们只需要删除这些文件监视器(在节点的情况下)

killall node

首先,你可以每次都以root权限运行 Sudo NPM启动 或者你可以删除node_modules文件夹,然后使用npm install重新安装 或者你可以得到永久的解决方案 fs.inotify回响。Max_user_watches =524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p