ubuntu 系统中运行 npm run dev 命令遇到错误,报错信息如下:
Error: ENOSPC: System limit for number of file watchers reached, watch '/www/wwwroot/booking.02405.com/vendor/phpunit/phpunit/src/Runner/ResultCache/Subscriber/TestPreparedSubscriber.php'
at FSWatcher.<computed> (node:internal/fs/watchers:244:19)
at Object.watch (node:fs:2315:34)
at createFsWatchInstance (file:///www/wwwroot/booking.02405.com/node_modules/vite/dist/node/chunks/dep-24daf00c.js:50429:17)
at setFsWatchListener (file:///www/wwwroot/booking.02405.com/node_modules/vite/dist/node/chunks/dep-24daf00c.js:50476:15)
at NodeFsHandler._watchWithNodeFs (file:///www/wwwroot/booking.02405.com/node_modules/vite/dist/node/chunks/dep-24daf00c.js:50631:14)
at NodeFsHandler._handleFile (file:///www/wwwroot/booking.02405.com/node_modules/vite/dist/node/chunks/dep-24daf00c.js:50695:23)
at NodeFsHandler._addToNodeFs (file:///www/wwwroot/booking.02405.com/node_modules/vite/dist/node/chunks/dep-24daf00c.js:50937:21)
Emitted 'error' event on FSWatcher instance at:
at FSWatcher._handleError (file:///www/wwwroot/booking.02405.com/node_modules/vite/dist/node/chunks/dep-24daf00c.js:52130:10)
at NodeFsHandler._addToNodeFs (file:///www/wwwroot/booking.02405.com/node_modules/vite/dist/node/chunks/dep-24daf00c.js:50945:18) {
errno: -28,
syscall: 'watch',
code: 'ENOSPC',
错误意思是系统监视的文件数量已达到限制!这是因为watch操作需要监听很多文件的改动,但是fedora、ubuntu等系统的文件句柄其实是有限制的。
解决办法是修改系统监控文件数,运行下面的命令即可:
$ echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p