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

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

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

希望能有所帮助!

其他回答

我在基于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

希望能有所帮助!

如果你在Docker中运行你的项目,你应该执行echo fs.inotify。Max_user_watches =524288 | sudo tee -a /etc/sysctl.conf和主机中的所有其他命令,因为容器将自动继承该设置(并且直接在其中执行将不起作用)。

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

删除react node_modules

rm -r node_modules

yarn or npm install

yarn start or npm start

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

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

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

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