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

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

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 ?


当前回答

要解决这个问题并不容易

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

然后运行你的项目。

如果有fs.inotify。在/etc/sysctl.conf文件中,Max_user_watches =524288, 执行相同的命令(echo fs.inotify。Max_user_watches =524288 | sudo tee -a /etc/sysctl.conf)。运行你的项目

其他回答

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

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

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

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

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

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

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

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

killall node

我通过使用sudo解决了这个问题 即

sudo yarn start

or

sudo npm start

使用sudo来解决这个问题将迫使观察者的数量增加,而不应用任何修改系统设置。不建议使用sudo来解决这类问题,尽管这是一个必须由您做出的选择,希望您明智地选择。

在我的Angular 13中,我添加了tsconfig.spec.json

 "exclude": [
    "node_modules/",
    ".git/"
  ]

谢谢反物质,它给了我诀窍。