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

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

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 ?


当前回答

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

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

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

其他回答

对于vs代码,请参阅此处的详细说明: https://code.visualstudio.com/docs/setup/linux#_visual-studio-code-is-unable-to-watch-for-file-changes-in-this-large-workspace-error-enospc

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

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

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

* * / node_modules

* * /构建

就是这样

我在linuxmint发行版上遇到了这个问题。当我在应用程序的/public文件夹中添加了很多文件夹和子文件夹/文件时,似乎就发生了这种情况。 我应用了这个修复,它工作得很好…

$ echo fs.inotify。Max_user_watches =524288 | sudo tee -a /etc/sysctl.conf . a

更改目录到/etc文件夹: cd /等

然后运行这个: Sudo systcl -p

你可能需要关闭你的终端,重新启动npm才能让它工作。

如果失败了,我建议全局安装react-scripts并直接运行你的应用程序。

$ NPM I -g保存反应脚本

然后不是NPM start run,而是脚本开始运行你的应用程序。

在我的Angular 13中,我添加了tsconfig.spec.json

 "exclude": [
    "node_modules/",
    ".git/"
  ]

谢谢反物质,它给了我诀窍。

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

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

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