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

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

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 ?


当前回答

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

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

我重新启动VM,它工作了

sudo重启

其他回答

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

sudo yarn start

or

sudo npm start

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

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

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

来自官方文件:

“Visual Studio Code无法监视此大工作区中的文件更改”(错误ENOSPC)

当你看到这个通知时,它表明VS Code文件监视器正在用完句柄,因为工作区很大,包含很多文件。可以通过运行以下命令查看当前限制:

猫/proc/sys/fs/inotify/max_user_watches

可以通过编辑将限制增加到最大值

/etc/sysctl.conf

并将这一行添加到文件的末尾:

fs.inotify.max_user_watches = 524288

然后可以通过运行加载新值

Sudo sysctl -p

请注意Arch Linux的工作方式略有不同,详细信息请参见增加inotify观察者的数量。

虽然524,288是可以观看的最大文件数量,但如果您处于内存特别受限的环境中,您可能希望降低这个数字。每个文件手表占用540字节(32位)或~1kB(64位),因此假设所有524,288块手表都被消耗掉了,结果是大约256MB(32位)或512MB(64位)的上限。

另一个选择

是排除特定的工作空间目录从VS Code文件监视器的文件。watcherExclude设置。文件的默认值。watcherExclude排除了node_modules和.git下的一些文件夹,但是你可以添加其他你不想让VS Code跟踪的目录。

"files.watcherExclude": {
    "**/.git/objects/**": true,
    "**/.git/subtree-cache/**": true,
    "**/node_modules/*/**": true
  }

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

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

解决方案:

修改系统监控文件个数

Ubuntu

Sudo gedit /etc/sysctl.conf

在底部加一条线

fs.inotify.max_user_watches = 524288

然后保存并退出!

Sudo sysctl -p

检查一下

那么问题就解决了!