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

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

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 ?


当前回答

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

其他回答

对于vs代码,请参阅此处的详细说明: https://code.visualstudio.com/docs/setup/linux#_visual-studio-code-is-unable-to-watch-for-file-changes-in-this-large-workspace-error-enospc

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

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

对之前答案的补充 有时我们使用监视器运行多个项目 因此,我们应该取消其余的项目,只运行当前的项目

因此,取消其他项目,只运行当前项目。

如果你已经添加了2个修复:fs.inotify.max_user_watches=524288

重启机器,一切都会恢复正常的 将引起问题的文件夹(对我来说是node_modules)重命名为任意名称(node_modilesa),然后重新命名。这将删除linux放在这些文件夹上的手表。允许您再次正常编码。