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

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

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 ?


当前回答

试试这个,我面对它很长一段时间,但最后它是这样解决的,

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

之后最重要的步骤是重新启动系统。

其他回答

试试这个,我面对它很长一段时间,但最后它是这样解决的,

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

之后最重要的步骤是重新启动系统。

fs.inotify回响。Max_user_watches =524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p

运行Npm后,在项目终端运行此代码

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

步骤1:停止服务器

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

步骤3:启动服务器

要解决这个问题并不容易

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

根本原因

上面的大多数回答都在谈论提高限制,而不是消除根本原因,这通常只是冗余监视的问题,通常是针对node_modules中的文件。

Webpack

答案在webpack 5文档中: watchOptions:{被忽略:/node_modules/}

只需在这里阅读:https://webpack.js.org/configuration/watch/#watchoptionsignored

文档甚至提到这是一个“提示”,引用如下:

如果观察对你不起作用,试试这个方法。这可能会有所帮助 NFS和VirtualBox、WSL、容器或机器中的问题 码头工人。在这些情况下,使用轮询间隔并忽略large 文件夹,如/node_modules/,以保持CPU的使用最小化。

VS代码

VS Code或任何代码编辑器也会创建大量的文件监视。默认情况下,其中许多是完全多余的。更多信息请点击:https://code.visualstudio.com/docs/setup/linux#_visual-studio-code-is-unable-to-watch-for-file-changes-in-this-large-workspace-error-enospc