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

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

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 ?


当前回答

在react.js中显示我同样的错误,我修复了这种方式,希望在react本机也能工作

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

sudo sysctl -p

现在你可以再次运行npm start。

npm start

其他回答

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

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

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

killall node

Linux使用inotify包来观察文件系统事件、单个文件或目录。

由于React / Angular会在保存时热加载和重新编译文件,所以它需要跟踪所有项目的文件。增加inotify监视限制应该会隐藏警告消息。

你可以试着编辑

# insert the new value into the system config
echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p

# check that the new value was applied
cat /proc/sys/fs/inotify/max_user_watches

# config variable name (not runnable)
fs.inotify.max_user_watches=524288

验证最简单的方法,它是为我工作良好。

步骤1:停止服务器

第二步:手动删除' '下的'cache'文件夹。Angular的文件夹

步骤3:启动服务器

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

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

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

希望能有所帮助!