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

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

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 ?


当前回答

我使用ubuntu 20服务器,我添加在文件:/etc/sysctl.conf下面一行

fs.inotify.max_user_watches = 524288

保存后执行sudo sysctl -p命令

在那之后,一切都很好!

其他回答

你可以修复它,增加inotify观察者的数量。

如果你对技术细节不感兴趣,只想要听工作:

如果您正在运行Debian、RedHat或其他类似的Linux发行版,请在终端中运行以下命令: $ echo fs.inotify。Max_user_watches =524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p 如果您正在运行ArchLinux,请运行以下命令 $ echo fs.inotify。Max_user_watches =524288 | sudo tee /etc/sysctl.d/40-max-user-watches.conf && sudo sysctl——系统

然后将其粘贴到您的终端,并按enter键运行它。


技术细节

Listen在Linux上默认使用inotify来监视目录的更改。系统限制可以监视的文件数量是很常见的。例如,Ubuntu Lucid(64位)的inotify限制设置为8192。

你可以通过执行以下命令来获得当前inotify文件的监视限制:

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

当此限制不足以监视目录中的所有文件时,必须增加该限制以使Listen正常工作。

你可以临时设置一个新的限制:

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

如果你想让你的限制永久化,可以使用:

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

如果listen一直抱怨,您可能还需要注意max_queued_events和max_user_instances的值。

设置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代码文件监视排除模式。这可能是最终的解决方案,我只是不确定你总是事先知道哪些文件你不感兴趣看。

另一个简单而好的解决方案是将这个添加到jest配置中:

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

这将忽略指定的目录,以减少被扫描的文件

我使用ubuntu 20服务器,我添加在文件:/etc/sysctl.conf下面一行

fs.inotify.max_user_watches = 524288

保存后执行sudo sysctl -p命令

在那之后,一切都很好!

试试这个,我面对它很长一段时间,但最后它是这样解决的,

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

之后最重要的步骤是重新启动系统。