Nodemon Error: System limit for number of file watchers reached
Nodemon Error: System limit for number of file watchers reached
我正在学习 graphql
并使用 prisma-binding
进行 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
您需要增加系统用户的 inotify 观察者限制。您可以从命令行执行此操作:
sudo sysctl -w fs.inotify.max_user_watches=100000
不过,这只会持续到您重新启动为止。要使其永久化,请添加一个名为 /etc/sysctl.d/10-user-watches.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
很难知道观察者的数量会增加多少。所以,这里有一个实用程序可以使观察者的数量增加一倍:
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=""
}
function double_inode_watchers() {
watcher_count="$(get_inode_watcher_count)"
set_inode_watchers "$((watcher_count * 2))"
if test "" = "-p" || test "" = "--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。谢天谢地,他们找到了一个很好的解决方案 on their site:
For some systems, watching many files can result in a lot of CPU or memory usage. It is possible to exclude a huge folder like node_modules using a regular expression:
webpack.config.js
module.exports = {
watchOptions: {
ignored: /node_modules/
}
};
就我而言,当我在 Linux 服务器中执行 nodemon 命令时。我打开 VSCode(通过 SSH 连接到服务器)。因此,根据@Juri Sinitson 的回答,我再次关闭 VSCode 和 运行 nodemon 命令。并且有效。
我的nodemon命令:
nodemon server.js
通过 npm 启动
我正在学习 graphql
并使用 prisma-binding
进行 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
您需要增加系统用户的 inotify 观察者限制。您可以从命令行执行此操作:
sudo sysctl -w fs.inotify.max_user_watches=100000
不过,这只会持续到您重新启动为止。要使其永久化,请添加一个名为 /etc/sysctl.d/10-user-watches.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
很难知道观察者的数量会增加多少。所以,这里有一个实用程序可以使观察者的数量增加一倍:
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=""
}
function double_inode_watchers() {
watcher_count="$(get_inode_watcher_count)"
set_inode_watchers "$((watcher_count * 2))"
if test "" = "-p" || test "" = "--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。谢天谢地,他们找到了一个很好的解决方案 on their site:
For some systems, watching many files can result in a lot of CPU or memory usage. It is possible to exclude a huge folder like node_modules using a regular expression:
webpack.config.js
module.exports = {
watchOptions: {
ignored: /node_modules/
}
};
就我而言,当我在 Linux 服务器中执行 nodemon 命令时。我打开 VSCode(通过 SSH 连接到服务器)。因此,根据@Juri Sinitson 的回答,我再次关闭 VSCode 和 运行 nodemon 命令。并且有效。
我的nodemon命令:
nodemon server.js
通过 npm 启动