You press Ctrl+Shift+F to search your project for one function name, and VS Code returns thousands of results, almost all of them from inside node_modules. The search takes ages, the results list is useless, and the editor slows down every time you try. The folder was never meant to be searched; it contains other people’s library code, not your work. The fix is to exclude it properly, and there are three levels of exclusion worth knowing.
This guide shows how to keep node_modules (and similar generated folders) out of VS Code search, how to still peek inside when you genuinely need to, and how the same settings also speed up the rest of the editor.
Quick Answer
To exclude node_modules from VS Code search, open Settings and make sure Search: Use Ignore Files is on so your .gitignore is respected, or add "**/node_modules": true under search.exclude in your settings. For an instant one-off fix, type files to exclude patterns in the search panel or add node_modules to the files-to-exclude box. Search results will then show only your own code and return almost instantly.
Why node_modules Pollutes Your Search Results
A typical JavaScript or TypeScript project installs hundreds of packages, and together they can contain 50,000 files or more. VS Code’s global search scans file contents, so every one of those library files is a candidate for every search. That is why a search for a common word like config or error explodes, and why searches in big projects feel slow even on a fast computer. Your own source might be 200 files; the search is wading through a quarter of a million.
The good news is that VS Code already ships with sensible defaults: node_modules and bower_components are excluded from search out of the box. If they are showing up anyway, something has overridden the default, or the folder in your project has a different name, such as a nested node_modules inside a package in a monorepo.
Method 1: Let Your .gitignore Do the Work
The cleanest long-term solution is to let VS Code follow your .gitignore file, because that file already lists everything that is not your source code:
- Open Settings with
Ctrl+,and search for Use Ignore Files. - Turn on Search: Use Ignore Files and Explorer: Use Ignore Files if you want the same behaviour in the file tree prompts.
- Make sure your project’s
.gitignorecontains a line withnode_modules(most project templates add it automatically). - Run your search again; ignored folders disappear from the results.
This approach stays correct as your project grows, because any folder you later add to .gitignore, such as dist or coverage output, is automatically excluded from search too.
Method 2: Set search.exclude Explicitly
If you prefer explicit control, add patterns to your settings file. Open Preferences: Open User Settings (JSON) from the Command Palette and add:
"search.exclude": {
"**/node_modules": true,
"**/bower_components": true,
"**/dist": true,
"**/build": true,
"**/.next": true
}The **/ at the start means the pattern matches at any depth, which matters in monorepos where packages have their own nested node_modules folders. Setting a pattern to true excludes it; setting one to false forces it back in, which is how you undo an exclusion later. The VS Code basics documentation on search explains how these glob patterns behave alongside the ignore-files options.
Method 3: Exclude for One Search Only
Sometimes you normally want broad results but need one focused search. Click the toggle in the search box labelled with an arrow, or expand the files to include and files to exclude fields under the search input. Typing node_modules in the exclude field filters just that search without changing any settings. You can also scope a search by right-clicking a folder in the Explorer and choosing Find in Folder, which searches only that part of the tree.
Related Settings That Speed Up the Whole Editor
Search is not the only feature slowed down by giant library folders. The same exclusion idea applies elsewhere:
files.excludehides folders from the Explorer sidebar entirely, which declutters the tree.files.watcherExcludestops VS Code from monitoring those folders for changes, cutting background CPU in the way described in our guide on why VS Code uses so much CPU in a large project folder.- Adding
"exclude": ["node_modules", "dist"]to atsconfig.jsonorjsconfig.jsonstops the TypeScript server from parsing library output files.
Applied together, these settings make a big project feel like a small one, because every background tool is suddenly working on your files only.
How to Search Inside node_modules When You Really Need To
Occasionally you do want to check how a library implements something. You have options that do not undo your exclusions: open the specific package folder from the Explorer and use Find in Folder on it, or set the search.exclude value for node_modules to false temporarily and run the search before switching it back. Reading a library’s source in the editor is also easier when you follow a definition with F12, which jumps straight to the relevant file without a global search at all.
Common Mistakes to Avoid
- Deleting node_modules to make search faster. Your project will simply break; reinstalling recreates the folder anyway.
- Using the wrong pattern.
node_moduleswithout**/may miss nested copies in subfolders; the glob prefix matters. - Editing workspace settings when you meant user settings. A workspace-only fix will not help your other projects.
- Assuming the default is broken. VS Code excludes
node_modulesby default, so if results include it, check for a settings override or afalsevalue someone added earlier.
Workspace Settings or User Settings: Which Should You Use?
Search exclusions can live in two places, and choosing the right one saves confusion later. Workspace settings, stored in the project’s .vscode/settings.json, apply only to that project, but they are shared with your team through version control, which is a real benefit: a new developer clones the project and instantly gets fast searches. User settings apply to every project on your machine, which is better for personal preferences and for folders that appear in all your projects, like node_modules.
A sensible split is to put universal generated folders in your user settings, and project-specific output folders, such as a custom build directory only this project has, in the workspace settings. If the same pattern exists in both places, the workspace value wins for that project. Whichever you choose, avoid scattering exclusions across both files with no pattern, or future you will struggle to work out why a folder is or is not being searched.
Conclusion
Slow, noisy search in VS Code is almost always a node_modules problem, and it is solved by exclusions, not by faster hardware. Turn on ignore-file support so your .gitignore is respected, back it up with explicit search.exclude patterns, and extend the same idea to the file watcher for a generally calmer editor. Your searches will return in a blink and show the code you actually wrote.
Frequently Asked Questions
Why is node_modules showing in my search if VS Code excludes it by default?
Usually because a settings file sets "**/node_modules": false, or because the results are coming from a different folder with a similar name. Check both your user settings and the project’s .vscode/settings.json for overrides.
What is the difference between search.exclude and files.exclude?
search.exclude controls which folders global search scans. files.exclude controls which files and folders appear in the Explorer sidebar. They are independent, and many people set both: hidden from the tree and skipped by search.
Does excluding node_modules affect IntelliSense or my build?
No. Your code still imports packages normally, jump-to-definition still works, and builds are untouched. The exclusion only changes what the search feature scans and lists.
How do I exclude node_modules in every project at once?
Put the search.exclude patterns in your user settings rather than a single workspace. User settings apply to every folder you open, while workspace settings affect only that project.
Can I search only one package inside node_modules?
Yes. Right-click the package’s folder in the Explorer and choose Find in Folder. The search runs just within that folder, ignoring the exclusion, which is perfect for reading library source code.


Leave a Reply