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

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

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 ?


当前回答

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

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

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

其他回答

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

要解决这个问题并不容易

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

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

步骤1:停止服务器

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

步骤3:启动服务器

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

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

#!/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,但是可以随意设置您想要的限制。

此错误的含义是系统监控的文件数量已达到限制!!

Result: The command executed failed!或者抛出一个警告(比如执行一个react-native start VSCode)

解决方案:

修改系统监控文件个数

Ubuntu

Sudo gedit /etc/sysctl.conf

在底部加一条线

fs.inotify.max_user_watches = 524288

然后保存并退出!

Sudo sysctl -p

检查一下

那么问题就解决了!