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

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

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/"]

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

其他回答

请参考此链接[1]。Visual Studio代码中提到了对此错误消息的简要解释。我也遇到了同样的错误。在相关文件中添加以下参数将修复此问题。

 fs.inotify.max_user_watches=524288

[1] https://code.visualstudio.com/docs/setup/linux#_visual-studio-code-is-unable-to-watch-for-file-changes-in-this-large-wor kspace-error-enospc

如果你已经添加了2个修复:fs.inotify.max_user_watches=524288

重启机器,一切都会恢复正常的 将引起问题的文件夹(对我来说是node_modules)重命名为任意名称(node_modilesa),然后重新命名。这将删除linux放在这些文件夹上的手表。允许您再次正常编码。

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

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

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

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观察者的数量,只需要点击链接。

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

sudo yarn start

or

sudo npm start

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