77

Is it possible to ignore searching the node_modules folder when using WebStorm's navigation pop-up window (Command + Shift + N)?

This makes it really annoying when wanting to quickly navigate to, for example, the package.json file.

1
  • FYI. You could include directory names in pattern, see help
    – de1mar
    Aug 30, 2013 at 14:50

8 Answers 8

122

To exclude the directory from being searched via navigation pop-up, pick node_modules directory in Project view, then from mouse context menu:

Mark Directory As -> Excluded

enter image description here

Directory could be restored via Preferences->Directories->Excluded Folders settings

11
  • 2
    Thanks! Using this in PhpStorm 8.
    – mikkelz
    Oct 9, 2014 at 12:48
  • 4
    Yep, still the same in Webstorm 11. Dec 22, 2015 at 9:06
  • 16
    Make sure your library references are setup properly if you do this. Otherwise Webstorm will no longer recognize functions and methods residing in node_modules. bit.ly/1J7XLD9
    – Lefka
    Dec 30, 2015 at 15:53
  • 1
    Works in IntelliJ as well
    – bicycle
    May 13, 2016 at 22:37
  • 1
    This recognizes type definitions, but not modules that augment them. For example importing rxj/Observable works, but it won't recognize Observable.map even if you import "node_modules/rxjs/add/operator/map.d.ts" explicitly. May 26, 2016 at 8:36
55

In Webstorm 8, you need to also visit Settings > JavaScript > Libraries and disable Node.js core modules and node_modules. The directory exclusion will then work as before.

11
  • This works for me. However, after I disable the Node.js dependencies, all the window variables got warning "Unresolved variable...". Any idea how to fix that?
    – bizi
    Apr 26, 2014 at 0:53
  • @bizi I think you can manually add the libraries you do need back in settings and keep those you don't need out. Also it seems this no longer works for me - the node_modules library is added back after removal on restart... May 17, 2014 at 2:13
  • 3
    When restarting WebStorm node_modules folder is again in Libriaries. Even if I remove it from there Webstorm is still indexing it so I restart, but node_modules folder is back in Libriaries. Is this a bug/feature? How to solve this. My pc is overheating because of this indexing. Sep 9, 2014 at 21:05
  • @Hoto I am experiencing the same thing, but I know that WebStorm uses the info in node_modules to know which packages you have installed. This info is used in the "Node.js and NPM" section in your preferences. I think it is unavoidable as long as you keep the "Node" plugin enabled. Once you disable Node you can successfully keep the directory excluded. But then you no longer can run and debug Node code, and you no longer have access to the Node predefined globals, which will then show up as errors.
    – oligofren
    Apr 18, 2015 at 14:18
  • 5
    I still have this issue in WebStorm 10.0.3 - I can't seem to remove node_modules from my search index, even though it is an excluded folder. Jun 5, 2015 at 14:19
24

To exclude node_modules/ files from being searched in "Navigate | File..." popup and to avoid indexing node_modules/ folder, please perform these steps:

  1. Mark node_modules/ folder as excluded in Settings | Directories.

  2. Remove "<your project name> node_modules" library in Settings | Languages & Frameworks | JavaScript | Libraries.

3
  • 2
    Thank you so much for this, I've been dying from the 20min long indexing in the larger projects Feb 26, 2016 at 15:50
  • Thank you so much, it's finally better solution for me. Jun 3, 2016 at 9:03
  • 6
    Doing number 2 is turning off syntax highlighting of members and methods that are defined in node_modules - I less recommend this.
    – chenop
    Oct 30, 2017 at 18:49
14

To exclude node_modules folder from all projects (only created after that change) you can add this folder to list of standard folders to ignore.

  1. Open PHPStorm, and close current project File > Close Project.
  2. On startup PHPStorm window click "Configure > Settings". enter image description here

  3. Then navigate to Build, Execution, Deployment > Deployment > Options.

  4. Now you can set node_modules or anyone else to exclude by default for all new projects. enter image description here

P.s. Closing the current project is very important. If you do this settings with active project, this will affect only current project.

2
  • 1
    and don't forget to do it again for your CURRENT PROJECT once you re-open it. Nov 8, 2021 at 0:50
  • The start up panel is now different in 2023. I don't see a Configure option in the new start up panel. Jul 17 at 16:10
3

Solution for those who has library imports not resolved after node_modules exclusion

As the accepted answer states, you should exclude node_modules folder, but then you'll get unresolved references for all stuff you import from your libraries. To resolve this issue you need to include explicitly node_modules folder to your list of libraries

enter image description here

2
  1. Exclude the directory: Mark the directory itself as excluded (Right-Click -> Mark Directory As -> Excluded). It might then already disappear.
  2. Hide excluded files: Tick the project pane option (under the Gear-Wheel symbol) and un-tick Show Excluded Files to hide excluded directories
0
1

I'm not sure why, but I saw lots of files with "spec" on Ctrl+Shift+n (I can't publish images, sorry :( )

I saw on the contextual menu over the node_modules: "Mark directory as": "excluded", "test sources root", "resources root"

I went to settings > directories, and I saw the node_modules with red color and can't change it, but, on the left there is list without header (?), I'm not sure if it is the exclude list, but, there is an X, I pushed on it, and restarted the IDE and it works!

If I see the contextual again, I see: "Mark directory as": "not exclude" and "test sources root". And in settings > directories I do not see on the lists, but red color on the folder node_modules (weird), I think it is so particular for this folder.

1

While webstorm tries to keep indexing everything inside your project - while if its a node project - the indexing takes forever, the better ways to exclude the node folder from indexing as below.

Select folder -- Settings|Directories -> Use Exclude - button on folder

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.