VSCode文件监视器ENOSPC错误咨询:无需提升fs.inotify.max_user_watches时如何终止文件监视器?/srv/路径匹配失败的正确配置模式是什么?
Hey there, let's work through these two file watcher issues you're facing with the ENOSPC: System limit for number of file watchers reached error in your Angular project.
1. Terminating VSCode File Watchers Without Increasing fs.inotify.max_user_watches
If you don't want to tweak system-level inotify limits, here are practical ways to reduce or stop VSCode's file watchers:
- Disable unused extensions: Many extensions (like linters, live reload tools, or code generators) run their own file watchers. Open the Extensions panel (
Ctrl+Shift+X), find extensions you're not actively using, disable them, and restart VSCode. This cuts down on redundant watchers immediately. - Exclude large/unnecessary folders from VSCode's watch list:
Open VSCode Settings (Ctrl+,), search forfiles.watcherExclude, then click "Edit in settings.json". Add paths you don't need VSCode to monitor—common culprits arenode_modules,dist, or system paths like/srv/. Example config:"files.watcherExclude": { "**/node_modules/**": true, "**/dist/**": true, "/srv/**": true, "**/.git/**": true } - Temporarily disable VSCode's core file watcher (last resort):
Add"files.watcherEnable": falseto yoursettings.json. Note: This disables real-time editor updates when files change, so only use this for quick fixes, not long-term development.
2. Correct Configuration to Match /srv/ Path in File Watchers
The issue likely stems from incorrect glob pattern matching. Here's how to fix it based on where you're configuring the watcher:
For VSCode's files.watcherExclude
VSCode uses glob patterns, and absolute paths need explicit root-level matching. To exclude the entire /srv/ directory and all its contents, use this pattern:
"files.watcherExclude": { "/srv/**": true }
- The
/at the start ensures it matches the root-level/srv/folder, not a folder namedsrvinside your project. **matches all subdirectories and files under/srv/.
For Angular's Build/Watch Configuration (angular.json)
If you're trying to exclude /srv/ from Angular's own file watcher (used during ng serve or ng build --watch), add the absolute path to the exclude array in your project's build options:
"projects": { "your-project-name": { "architect": { "build": { "options": { "exclude": [ "/srv/**/*" ] } } } } }
- Double-check path case sensitivity (Linux systems are case-sensitive—if the folder is
/SRV/,/srv/**won't match). - Ensure no more specific glob patterns are overriding your rule (e.g., if you have
/srv/specific-folder/**set to be watched, it will take priority over a general/srv/**exclude rule).
内容的提问来源于stack exchange,提问作者Greg

