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

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

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)。运行你的项目

其他回答

记住这个问题是重复的:见原问题的答案

解决我问题的一个简单方法是:

npm cache clear 

今天的最佳实践是

npm cache verify 

NPM或者由它控制的进程正在监视太多的文件。更新构建节点上的max_user_watches可以永远修复它。对于debian,在终端上放以下命令:

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

如果你想知道如何增加inotify观察者的数量,只需要点击链接。

迟回答,已经有很多好的答案了。

如果你想要一个简单的脚本来检查最大文件监视是否足够大,如果不够大,就增加限制,下面是:

#!/usr/bin/env bash

let current_watches=`sysctl -n fs.inotify.max_user_watches`

if (( current_watches < 80000 ))
then
  echo "Current max_user_watches ${current_watches} is less than 80000."
else
  echo "Current max_user_watches ${current_watches} is already equal to or greater than 80000."
  exit 0
fi

if sudo sysctl -w fs.inotify.max_user_watches=80000 && sudo sysctl -p && echo fs.inotify.max_user_watches=80000 | sudo tee /etc/sysctl.d/10-user-watches.conf
then
  echo "max_user_watches changed to 80000."
else
  echo "Could not change max_user_watches."
  exit 1
fi

脚本将限制增加到80000,但是可以随意设置您想要的限制。

如果你使用vs代码编辑器,由于项目中有大量文件,任何编辑器都会出现错误。Node_modules和build不需要,所以在列表中删除。所有打开在vs代码文件菜单

你必须过滤不必要的文件夹文件侧边栏

进入代码>首选项>设置 在搜索设置中搜索关键字“文件:排除” 添加pettern

* * / node_modules

* * /构建

就是这样

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

sudo yarn start

or

sudo npm start

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

我试着增加建议的数量,但它没有工作。

我看到当我登录我的虚拟机时,它显示“需要重新启动”

我重新启动VM,它工作了

sudo重启