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?

5
28 comments

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

-1

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 :)

2

>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

1

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?)

1

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

1

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.

1

Can't reproduce in 2020.3.2 when using In Project scope

Do you have node_modules  excluded?

0

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?

2

>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)

1

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.

4

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

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.

1

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

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

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

My project started acting this way too where Find in Files was including items from node_modules. The interaction between Elena Pogorelova and @... 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.

2

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.

2

Any update or roadmap about this issue?

2

Yoann Haffner, like Andrew Blair mentioned, the fix is to remove the .idea directory, so it can be recreated on the next start-up.

0

I am not happy to be the first commenter in 2023 on this ludicrous issue! I can't believe it's 7 years already since 2016!

To rephrase the issue: The user should be able to select a directory (and NOT the whole project) and inside there search without bumping into node_modules, build/, dist/, cover/ or the other myriad filetypes they want to .gitignore or .npmignore or .whateverignore anyway. 

This could be implemented in a myriad of ways:

- an easy setting, a few clicks away, depending on the project

- allow me to select which .ignore files should be considered in a new scope I'm making.

- some ready-made easy to grab patterns, right on the IDE (depending on the project type also) that users select easily instead of having to search google for it and read a hudred comments of frustrated deserters! 

- a ready made scope setting exactly for this!

- an .ignorefilesinsearch or something, which is my least favorite one, cause some times when I do want to search in my node_modules, I'll have to edit that which feels kinda weird.

I'm sure there are another so many, but you choose to do NOTHING!

IntelliJ people, listen to your customers, do your BASICS first and then cover every new shiny CSS meta-meta-framework that has a 1000 stars on Github. 

3

Ok, this is getting worse! I had ChatGPT digest my .gitignore file and bring it to this format

!file:*coverage//**&&!file:*node_modules//**

It spit out this :

!file[*]:**.cache//*&&!file[*]:**.eslintcache//*&&!file[*]:**.grunt//*&&!file[*]:**.idea//*&&!file[*]:**.lock-wscript//*&&!file[*]:**.next//*&&!file[*]:**.node_repl_history//*&&!file[*]:**.npm//*&&!file[*]:**.nuxt//*&&!file[*]:**.nyc_output//*&&!file[*]:**.serverless//*&&!file[*]:**.vuepress/dist//*&&!file[*]:**.yarn-integrity//*&&!file[**]:*DRAFT//*&&!file[*]:*bower_components//*&&!file[*]:*build//*&&!file[*]:*coverage//*&&!file[*]:*dist//*&&!file[*]:*jspm_packages//*&&!file[*]:*lib-cov//*&&!file[*]:*logs//*&&!file[*]:*node_modules//*&&!file[*]:*pids//*&&!file[*]:*typings//*&&!file[*]:**.log&&!file[*]:**.pid&&!file[*]:**.pid.lock&&!file[*]:**.seed&&!file[*]:**.tgz&&!file:*npm-debug.log*&&!file:*yarn-debug.log*&&!file:*yarn-error.log*

It works almost perfectly... me and the AI did it. BUT...!

But the node_modules contents are NOT ignored! All other exclusions work perfect, but not node_module, the elephant in the room. Its as if they are hardcoded to be included! This is INSANITY people! Or maybe AI's greatest enemy, Natural Stupidity! I've lost my whole day trying to fix this, still broken!

I'm going to open a support ticket, this is ludicrus. 

1

As it's mentioned in the comments above, 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

1

The solutions from the comments above weren't clear at first. You would need to prefix the above mentioned entire pattern in order for your pattern to work when you specify a scope. say if you want to exclude node_modules then do 

file[*]:*/&&!file[*]:node_modules//*
0

I can't comprehend how it is possible to ignore the users and developers feedback on your Search feature. Any time I am using it I feel like I am shuffling through the pile of … with a ridiculous solutions like ignoring mask: “!node_modules*,!.build*,!*.d.ts,!*.js,!*-d.ts,!*-d.tsx,!*.cts”. Using methods you recommend causes side effects somewhere else; disappearing files and so on. It is unintentional and not expected! The only solution is to spend a day googling or hire a dedicated contractor “JetBrains search specialist”. With overall WebStorm and Intellij being good editors this is by far the worst way of solving problem you could come up with. You have to try very very hard to complicate it so much by providing so many unnecessary features against all “customer feedback first” software delivery practices. Please just don't say: “Our devs LOVE this feature”. 

In milions of software projects, there is 90% of similar files we exclude. Can you just make the option “Exclude from Search” truly exclude from search - NOT just for the specific dropdown scenario telling us to use regex and masks? Please, as a long lasting customer, fix it once forever.

 

1

Just want to thanks IntelliJ, I had to stop using it because 1) my hands can't take all the clicking and 2) the problem discussed here that never got resolved. So thanks now I'm a happy vim user.

0

This daunting and NOT YET really SOLVED issue needs the attention of a high level Product Manager for prioritization. 

It's ludicrus that so many years later you cant provide an EASY & STRAIGHT-FORWARD way to exclude some standard stuff like node_modules. Or make a UI that auto generates your silly esoteric regex-like thingy. Or hard code tha damn thing, with a checkbox, it's a few lines of code. 

You're losing customer cause you're not listening, I know people that are so fed up with this that go to VSCode…. 

1

Fixing https://youtrack.jetbrains.com/issue/WEB-25810/Show-nodemodules-folder-when-configuring-scopes should make configuring scopes easier.

Until it's implemented, I can suggest either using the In Project scope that doesn't include libraries or creating custom scope with the regexp mentioned above (file[*]:*/&&!file[*]:node_modules//*) as suggested above.

0

Please sign in to leave a comment.