我正在学习GraphQL,并且在GraphQL操作中使用棱镜绑定。当我启动我的Node.js服务器时,我面临这个nodemon错误,它给了我一个由graphql-cli自动生成的模式文件的路径。这个错误是关于什么的?

错误:

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


当前回答

这是Linux内核中inotify (inode notify)的问题,可以通过下面的命令来解决:

对于临时解决方案,直到重新启动pc,使用以下命令 Sudo sysctl -w fs.inotify.max_user_watches=100000 一个永久的解决方案:为了使这个问题永久存在,添加一个名为/etc/sysctl.d/10-user-watch .conf的文件,包含以下内容: fs.inotify。Max_user_watches = 10000

在进行更改之后,使用sudo sysctl -p重新加载/etc目录下所有sysctl配置文件中的设置。

其他回答

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

function get_inode_watcher_count() {
  find /proc/*/fd -user "$USER" -lname anon_inode:inotify -printf '%hinfo/%f\n' 2>/dev/null | 
  xargs cat | 
  grep -c '^inotify'
}

function set_inode_watchers() {
  sudo sysctl -w fs.inotify.max_user_watches="$1"
}

function double_inode_watchers() {
  watcher_count="$(get_inode_watcher_count)"
  set_inode_watchers "$((watcher_count * 2))"

  if test "$1" = "-p" || test "$1" = "--persist"; then
    echo "fs.inotify.max_user_watches = $((watcher_count * 2))" > /etc/sysctl.d/10-user-watches.conf
  fi
}

# Usage
double_inode_watchers
# to make the change persistent
double_inode_watchers --persist

我也有同样的问题。然而,我的是来自Webpack的。值得庆幸的是,他们的网站上有一个很好的解决方案:

对于某些系统,查看许多文件可能会导致大量CPU或内存使用。可以使用正则表达式排除像node_modules这样的大文件夹:

文件webpack.config.js

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

这是Linux内核中inotify (inode notify)的问题,可以通过下面的命令来解决:

对于临时解决方案,直到重新启动pc,使用以下命令 Sudo sysctl -w fs.inotify.max_user_watches=100000 一个永久的解决方案:为了使这个问题永久存在,添加一个名为/etc/sysctl.d/10-user-watch .conf的文件,包含以下内容: fs.inotify。Max_user_watches = 10000

在进行更改之后,使用sudo sysctl -p重新加载/etc目录下所有sysctl配置文件中的设置。

您需要增加系统用户的inotify监视者限制。你可以在命令行中使用:

sudo sysctl -w fs.inotify.max_user_watches=100000

不过,这种情况只会持续到重新启动为止。要使其永久存在,添加一个名为/etc/sysctl.d/10-user-watch .conf的文件,包含以下内容:

fs.inotify.max_user_watches = 100000

在进行上述(或任何其他)更改之后,您可以使用sudo sysctl——system从/etc中的所有sysctl配置文件中重新加载设置。(在旧系统上,您可能需要使用sudo sysctl -p来代替。)

在Linux上,我实际上是用sudo运行的。 Sudo NPM启动