Custom Search - exclude all node_modules recusively
Answered
Hi
I would like to create a custom search in Find In Path , to exclude all node_modules recursively
I coudnt find an easy way , . The only way I can see , is going inside the project tree and excluding each node_module folder one by one.
This is a very hard way of doing it.
I would like a clever way of doing it . filter all folders called node_module recusively.
What pattern can I use.
Thanks.
Please sign in to leave a comment.
Mark directory as/Excluded in folder right-click menu excludes the folder recursively - all files/subfolders of excluded folder are excluded.
Note also that you can create a custom scope with node_modules folder excluded recursively (Settings/Preferences | Appearance & Behavior | Scopes) and use this scope when searching in Find In Path
Hi Elena
I know what you said , this doesnt help me.
My problem is that I have a very large tree with many folders and sub folders and each one contains a node_module folder. I do not want to go and exclude each node_module folder seperately. I would like to just set the pattern that it ignores all node_module folders recursively
can't you create the corresponding scope then? Like !file[your_project]:*node_modules//*
Hi Elena
This is exactly what I was looking for
Thanks thats great.
Doesn't work.... never have I ever had a software that was such a pain to search. A million features, but the important ones, don't work. I wish they'd stop spending time on features that no one uses and just fix the basic functionality!
You must have faced the issue because
node_modules
are only partially excluded - direct dependencies listed in package.json are added to JavaScript libraries and thus included.Use In Project scope for searching. JavaScript libraries are only included when using Directory scope with corresponding folder selected, or when using custom scope with explicit filters
Hi Elena,
So for the node_modules that are part of the JavaScript libraries can these be excluded in the custom scope? In the more recent version of IntelliJ is there a different way to have node_modules excluded from searching (such as find usage) but still be available for completion. FYI, I can't make the directory as excluded because this makes it so the classes aren't available for completion. Thanks!
Excluding libraries from custom scope is a bit tricky... To make it work, you need to prefix your scope pattern with
file[your_project_name]:*/&&
to overwrite the default scope - see https://youtrack.jetbrains.com/issue/IDEA-145142#comment=27-1156171 for explanationRelated feature request: : https://youtrack.jetbrains.com/issue/IDEA-103560
Thanks Elena, it worked! Let me now if this is a enhancement request to handle this is a more straightforward way.
FYI, I see you referred to the feature request. FYI, when the node_modules is setup as a library root then just searching for project files excludes these, which is exactly what I needed.
I'm using yarn classic workspaces which creates a node_modules for each workspace. I'm on WebStorm 2023.2.4.
I could not find a Scope pattern that excludes all node_modules and their contents.
I'm also missing the "External Dependencies" node when I edit a custom scope. That solution was described in feature request https://youtrack.jetbrains.com/issue/IDEA-103560
Here's the manual process I followed to exclude all
node_modules
from search without creating a bunch of unresolved variables:node_modules
directory.If you don't do this first, the root node_modules will be unselectable later.
node_modules
directories.node_modules
directory, right-click it and Mark Directory as > Excluded.I hope the JetBrains team makes an easier workflow for those of us with multiple node_modules. I found this experience pretty frustrating, and this manual solution is not future-proof since it will break when I add new workspaces.
You can use In Project scope when searching - it doesn't include libraries, so you won't see files from
node_modules
in search result when using it. JavaScript libraries are only included when using Directory scope with corresponding folder selected, or when using custom scope with explicit filters. To exclude libraries from custom scope, you need to prefix your scope pattern withfile[your_project_name]:*/&&
to overwrite the default scope as it's explained abovePlease vote for https://youtrack.jetbrains.com/issue/WEB-25810 to get notified when it's fixed