How to exclude node_modules and .meteor from all searches and code inspections

Is there some way to exclude the node_modules and .meteor folders from all code inspections and searches, but still have JS "import" autocomplete for npm packages?

18 comments
Comment actions Permalink

You can create a custom scope with node_modules and .meteor excluded in Preferences/Appearance & Behavior/Scopes and choose it for inspections/Find in Path. Note also that inspections are not enabled for library files, so adding these folders to JavaScript libraries turns inspections off for them

0
Comment actions Permalink

I'm having the same problem - when I search for symbols I know are in my code, I sometimes get results from some deep dependency of some library I don't care about.

I've tried creating a Scope, but I don't see any node_modules folder to ignore. Perhaps because non-project files are not shown?

1. I think that by default, searching should not look in node_modules, given how many dependencies even the simplest Node project tends to pull in. Is that something that the JetBrains team can consider?

2. For Find in Path, the developer can choose a custom scope. How can I choose one for search activated by double-pressing Shift?

3. Can you clarify what this means: "inspections are not enabled for library files, so adding these folders to JavaScript libraries turns inspections off for them"? If I exclude node_modules, I won't get code autocomplete suggestions for methods defined in those libraries? Hopefully I'm mistaken :)

1
Comment actions Permalink

>I think that by default, searching should not look in node_modules, given how many dependencies even the simplest Node project tends to pull in. Is that something that the JetBrains team can consider?

node_modules are only partially excluded - direct dependencies listed in package.json are added to JavaScript libraries and thus included in index.

Project scope doesn't include libraries, so you can use it if you don't like to see files from node_modules in search result.

JavaScript libraries are only included when using Directory scope with corresponding folder selected, or when using custom scope with explicit filters. 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 explanation

Related feature request: : https://youtrack.jetbrains.com/issue/IDEA-103560

 

>2. For Find in Path, the developer can choose a custom scope. How can I choose one for search activated by double-pressing Shift?

 

No way, please vote for https://youtrack.jetbrains.com/issue/IDEA-117466 and linked tickets

 

>3. Can you clarify what this means: "inspections are not enabled for library files, so adding these folders to JavaScript libraries turns inspections off for them"?

 

if you open a file from a library in the editor, you will see that the highlighting level is set to Syntax or NONE for them - i.e. the editor doesn't report errors in these files. But they are still indexed for completion, so that you get suggestions from library files in your source code

 

>If I exclude node_modules, I won't get code autocomplete suggestions for methods defined in those libraries? Hopefully I'm mistaken :)

 

if you exclude them completely, you won't get code completion for library methods - excliuded files are not indexed and thus aren't available in completion

0
Comment actions Permalink

Thank you Elena.

There's something wrong with the Shift+Shift search: sometimes it just doesn't show any project-specific items. In the screenshot below, I expect to see the .eslintrc from my project, but I only see ones from libraries:

I can't reliably reproduce this so I haven't filed a ticket yet, but does WebStom prioritize project matches vs. 3rd party library ones? (I assume it does... any idea what might happening here?)

0
Comment actions Permalink

Files from libraries shouldn't normally be includeed at all unless the Include non-project files is selected...

0
Comment actions Permalink

Elena Pogorelova You write in 2019:

Project scope doesn't include libraries, so you can use it if you don't like to see files from node_modules in search result.

With WebStorm 2020.3.2, I do see files from `packages/app/node_modules/@firebase/auth/dist/esm2017`, for example, in the Cmd-Shift-F > Scope > Project search.

0
Comment actions Permalink

Can't reproduce in 2020.3.2 when using In Project scope

Do you have node_modules  excluded?

0
Comment actions Permalink

Elena Pogorelova

This is easily a one-on-one support request, but it's my #1 annoyance with WebStorm (or... likely the only one; LOVE the product!!).

The attached screenshot may help you:

1. My project has multiple subprojects. Thus `packages/app` shown here.

2. Its `node_modules` is excluded but `node_modules/@firebase` is not excluded, so that symbols would be resolved from there (very vital, to be able to learn the APIs within the IDE, by diving into the type files).

3. However, look at the search results: all of those are from the library, not my code.

Can you tell if I'm doing something wrong?

1
Comment actions Permalink

>Its `node_modules` is excluded but `node_modules/@firebase` is not excluded

that's the issue, in your case it's not a library but just an additional project root, that's why it's processed when using In Project scope. You must have changed the default IDE settings (by default, it auto-excludes the node_modules but adds direct dependencies to a library, you must have deleted the library and marked certain packages not excluded instead)

0
Comment actions Permalink

five years after and there is still no easy way to hide content from node_modules and build folders etc. This makes all searching and all navigation features more or less useless. Why not just make a .riderignore file or something? quick and easy. I can't believe emacs and vim are actually beating you to the punch here. Yes actually language support is excellent but so many other features that just outta work are just being silently ignored. I do believe you recognize that LSP is on the rise? that means serious competition from emacs and vim, who has those things right. Why would anyone pay for rider then? please consider that we are programmers and navigation is key or we will go somewhere else.

2
Comment actions Permalink

Build folders can be excluded easily by marking them excluded.

Also, in v. 2021.1 there is External Dependencies node is Scopes which could be included/excluded directly, which should help excluding node_modules, see https://youtrack.jetbrains.com/issue/IDEA-103560

0
Comment actions Permalink

I did use this way (which is an annoying way, I'm tired of clicking and dragging and dropping my self through rider each day, but that's another story) but that doesn't prevent it from turning up in search result. Sorry for sounding angry, but it's annoying that you don't concentrate on the basics, and instead focus on supporting every new and shiny js framework under the sun.

0
Comment actions Permalink

I think there's a communication misunderstanding here, between Elena and the users suffering from this.

I am one. I wish my Find in Files > Project search would work as mentioned above:

Project scope doesn't include libraries, so you can use it if you don't like to see files from node_modules in search result.

JavaScript libraries are only included when using Directory scope with corresponding folder selected, [...]

That is fair. Only I've managed to somehow affect the project's configuration so that this no longer is true. Will look into this better during the week - hopefully being able to make a reproducible case. That could help us communicate about the same thing.

0
Comment actions Permalink

I have read that comment, and I do not disagree.

The problem is, I don't know how to find what I've changed in the settings. And that's fine. I'll gradually move to new clones and consider this water under the bridge.

0
Comment actions Permalink

Search in general in Rider(and all other jb products) is simply not on par on what I would expect from something that actually cost money. The fact that I have to use the mouse to select where I am searching and what files I'm searching is such an annoyance that I have seen my productivity drop below my vc code using colleagues. That I manually have to go through the entire codebase to "exclude" every *.min.js is not only annoying, it's simply impossible, unless you like to get fired because you spent an entire day ignoring javascript files. Unfortunately this has driven me to use VCCode and if that fails, I know Emacs can do most of what I want..I might try Rider again in a few years.

Perhaps you should concentrate more on the basics instead of supporting every insignificant js framework under the sun. We do know how to write our own code. In this case, a simple ".riderignore" file, and a little more keyboard friendly search interface, such that all other search tools have (and yes you are a search tool) could have prevented a loss of a customer.

1
Comment actions Permalink

My project started acting this way too where Find in Files was including items from node_modules. The interaction between Elena Pogorelova and Asko Kauppi led me to look a little closer and I saw that while Webstorm's docs say that node_modules should read as "library root" in the Project window by default, automatically. In my case it did not read as such, nor was it excluded or marked as anything in the Mark Directory As menu.

I can only surmise that my settings got corrupted somehow – or like Asko – I can't figure out what changed. So as a workaround I did the following:

1. Took screenshots of any important settings like Run Configurations
2. Quit Webstorm
3. Renamed /.idea to /.idea.bak
4. Started Webstorm and set up a new project using the existing project directory
5. Reinstated my Run Configurations referencing my screenshots and other settings 

The node_modules now reads, "library root" next to it and I'm getting the expected behaviour when I search files.

1
Comment actions Permalink

I can't believe this is still an issue and a pretty annoying one for a simple thing that others FREE IDE's got it sorted out.

I have tried to exclude the node_modules in so many ways and I still get results from it. This should be a simple setting.

I can say that if Github Copilot comes to Emacs, I will return to it. Webstorm has a pretty interface and debugging feature. But I can do without it. I need the essential stuff working first. And searching accurately is vital for my daily needs.

0

Please sign in to leave a comment.