Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/39.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js Nodemon错误:已达到文件监视程序数量的系统限制_Node.js_Graphql_Nodemon - Fatal编程技术网

Node.js Nodemon错误:已达到文件监视程序数量的系统限制

Node.js Nodemon错误:已达到文件监视程序数量的系统限制,node.js,graphql,nodemon,Node.js,Graphql,Nodemon,我正在学习graphql并使用prisma绑定进行graphql操作。我在启动节点服务器时遇到了这个nodemon错误,它给了我一个由graphql-cli自动生成的模式文件路径。谁能告诉我这个错误是怎么回事 错误: Internal watch failed: ENOSPC: System limit for number of file watchers reached, watch '/media/rehan-sattar/Development/All projects/GrpahQl/

我正在学习
graphql
并使用
prisma绑定
进行graphql操作。我在启动节点服务器时遇到了这个
nodemon
错误,它给了我一个由
graphql-cli
自动生成的模式文件路径。谁能告诉我这个错误是怎么回事

错误:

Internal watch failed: ENOSPC: System limit for number of file watchers reached, watch '/media/rehan-sattar/Development/All projects/GrpahQl/graph-ql-course/graphql-prisma/src/generated

在我的Ubuntu机器上使用VSCode时,我有时会遇到这个问题

在我的情况下,以下解决方法有助于:


停止观察程序,关闭VScode,启动观察程序,再次打开VScode。

在Linux上,我实际上已经使用sudo运行过。
sudo npm start

您需要增加系统用户的观察者限制。可以通过以下命令行执行此操作:

sudo sysctl -w fs.inotify.max_user_watches=100000
不过,这只会持续到您重新启动。要使其永久化,请添加名为
/etc/sysctl.d/10 user watchs.conf
的文件,该文件包含以下内容:

fs.inotify.max_user_watches = 100000

在进行上述(或任何其他)更改后,您可以使用
sudo sysctl-p

/etc
中的所有sysctl配置文件重新加载设置。如果您使用的是Linux,您的项目将达到系统的文件监视程序限制

要解决此问题,请在终端上尝试:

echo fs.inotify.max_user_watches=524288 | sudo tee-a/etc/sysctl.conf&&sudo sysctl-p
为了测试更改,我将参数临时设置为值524288

sysctl -w fs.inotify.max_user_watches=524288
然后我继续验证:

npm run serve
问题已经解决,为了使其永久化,您应该尝试在文件“/etc/sysctl.conf”中添加一行,然后重新启动sysctl服务:

cat /etc/sysctl.conf |tail -n 2
fs.inotify.max_user_watches=524288

sudo systemctl restart systemd-sysctl.service

很难知道观察者的数量要增加多少。因此,这里有一个实用程序可以将观察者的数量增加一倍:

函数get\u inode\u watcher\u count(){ find/proc/*/fd-user“$user”-lname anon_inode:inotify-printf'%hinfo/%f\n'2>/dev/null | 沙尔格斯猫 grep-c“^inotify” } 函数集\u inode\u watchers(){ sudo sysctl-w fs.inotify.max_user_watches=“$1” } 函数double_inode_watchers(){ watcher\u count=“$(获取inode\u watcher\u count)” 设置观察者“$((观察者计数*2))” 如果测试“$1”=”-p“| |测试“$1”=”--persist”;则 echo“fs.inotify.max_user_watches=$((watcher_count*2))”>/etc/sysctl.d/10-user-watchs.conf fi } #用法 双inode观察者 #使更改持久化 双inode观察者——坚持
我也遇到了同样的问题,但我的问题来自网页包。谢天谢地,他们找到了一个很好的解决方案:

对于某些系统,查看许多文件可能会导致大量CPU或内存使用。可以使用正则表达式排除大型文件夹(如node_模块):

webpack.config.js

module.exports = {
  watchOptions: {
    ignored: /node_modules/
  }
};

在我的例子中,当我在Linux服务器上执行nodemon命令时。我打开了VSCode(SSH到服务器)。因此,根据@Juri Sinitson的回答,我只需关闭VSCode并再次运行nodemon命令。它是有效的

我的nodemon命令:
nodemon server.js
通过npm start

这是linux ulimit错误,请参见此处尝试此错误!再次出现同样的错误!您可能正在查看太多的文件。也许它还包括nod_模块目录?
node_模块
是必不可少的,因为所有的包都在那里。我曾试图杀死服务器端口上运行的以前的进程,这对我来说很有效,但我不知道现在需要多长时间:这通常会起作用,因为root用户通常比普通用户具有更高的inotify监视限制,但在不需要时以root用户的身份运行是一个非常糟糕的主意。查看如何更改用户限制。没错!因为VSCode。它应该是自动保存模式。这对我很有效;与ember合作开发非常感谢!为我工作!!但是我必须在哪里添加这个文件呢?@RehanSattar创建一个文件
/etc/sysctl.d/10 user watchs.conf
,并在其中放入
fs.inotify.max_user_watchs=100000
。为了完整起见,将这个文件放在这里
echo fs.inotify.max_user_watchs=100000 | sudo tee/etc/sysctl.d/10-user-watchs.conf&&sudo sysctl-p
。使用
sysctl--系统
要为较新系统重新加载请参见sysctl--system要为较新系统重新加载执行此操作时,我们是否必须知道其他含义?我知道这有助于解决问题,我自己也尝试过。但是我有点怀疑这个修复可能会造成什么副作用。@Aldee关于这个改变的技术含义,我建议查看这个wiki:这也解决了npm插件的很多问题。如果您不确定使用了多少,thxI不会建议增加这么多。使用下面的
find/proc/*/fd-user“$user”-lname anon_inode:inotify-printf'%hinfo/%f\n'2>/dev/null | xargs cat | grep-c'^inotify'
此测试提示是无价的。非常感谢。