Why VS Code’s File Explorer Flickers During npm Install and How to Fix It
During npm install, VS Code’s file explorer sometimes flashes due to misconfigured file‑watcher exclusions for node_modules, a bug in RPC argument handling and cancellation token processing; this article explains the root causes, demonstrates the faulty configurations, and provides concrete fixes and contribution tips.
Shaking node_modules
When running npm install, the file tree on the left may flash briefly, especially with many dependencies. The file watcher monitors the workspace and updates on changes, but excludes non‑source directories like .git and node_modules using a default glob configuration.
export const fileWatcherExcludes = [
'**/.git/objects/**',
'**/.git/subtree-cache/**',
'**/node_modules/**/*'
];The configuration appears correct, yet the logs show the setting filesWatcherExclude being applied:
[node:log] set watch file exclude: [
[
'**/.git/objects/**',
'**/.git/subtree-cache/**',
'**/node_modules/**/*'
]
]Through an RPC call, the value is transformed into [['xxx', 'yyy']], adding an extra array layer that the glob parser misinterprets.
[
{ allPaths: ['./0'] },
{ allPaths: ['./1'] },
{ allPaths: ['./2'] },
{ allPaths: ['./length'] }
]The correct parsing should yield paths like './.git/objects/', './.git/subtree-cache/', and './node_modules'. The mis‑parsing means the exclusion never actually takes effect.
Root cause in RPC handling
The KAITIAN front‑end communicates with the back‑end via vscode-jsonrpc. Calls automatically append a CancellationToken argument, which can clash with single‑array parameters. KAITIAN wraps a single array [xxx] into [[xxx]] to avoid this, but the back‑end does not unwrap it, causing setWatchFileExcludes to receive [['**/node_modules/**/*']] instead of the intended array.
function serializeArguments(args: any[]): any[] {
const maybeCancellationToken = args[args.length - 1];
if (
args.length === 2 &&
Array.isArray(args[0]) &&
maybeCancellationToken.hasOwnProperty('_isCancelled')
) {
return [...args[0], maybeCancellationToken];
}
return args;
}
callRPCService(...this.serializeArguments(args));Fixing the issue simply requires expanding the array when this pattern is detected.
File watcher exclusion patterns
VS Code’s default exclusion for node_modules is **/node_modules/**/*, which ignores all events in that folder. Monitoring the entire folder is too costly for large projects. The ideal behavior is to watch only the top‑level node_modules and its first‑level subfolders.
On Windows the pattern used is **/node_modules/*/**, while on macOS/Linux it is **/node_modules/**. Testing with Glob Online shows the former matches only first‑level subdirectories, the latter matches everything.
This is due to the files.watcherExclude setting ignoring changes to the node_modules folder because it can generate a huge number of file events, so the changes are ignored for performance reasons.
Removing the isWindows check on macOS allows the watcher to monitor the top‑level node_modules while still ignoring deeper directories.
Shaking diagnostics
A separate bug causes the diagnostics panel to flicker when any setting is changed while a JavaScript/TypeScript file is open. The TypeScript language service re‑fetches diagnostics on each setting change, triggering a UI refresh.
The underlying code checks whether diagnostic settings have changed:
// always returns true
function areLanguageDiagnosticSettingsEqual(currentSettings: LanguageDiagnosticSettings, newSettings: LanguageDiagnosticSettings): boolean {
return currentSettings.validate === newSettings.validate &&
currentSettings.enableSuggestions &&
currentSettings.enableSuggestions;
}VS Code 1.58 later fixed this issue.
Contributing fixes to VS Code
The article also outlines how to contribute patches: create an issue, reference it in the PR (e.g., **This PR fixes #<issueid>**), and follow the repository’s contribution guidelines.
For bugs without existing issues, open a new issue first; for labeled “bug” or “help‑wanted” issues, indicate willingness to submit a PR.
Images illustrating the problems and the VS Code settings UI are included throughout the article.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Taobao Frontend Technology
The frontend landscape is constantly evolving, with rapid innovations across familiar languages. Like us, your understanding of the frontend is continually refreshed. Join us on Taobao, a vibrant, all‑encompassing platform, to uncover limitless potential.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
