How to unexclude node_modules in 2016.2.2?

Since upgrading to WebStorm 2016.2.2, it's auto-excluding my node_modules folder. Note that this folder contains my source code, it's not generated by `npm install` or similar. The effect is now I can't find files with shift+shift or cmd-shift-o. If I repeat the shortcut (like cmd-shift-o, cmd-shift-o), that toggles "Include non-project files", and then it can find my files.

It doesn't seem possible to "unexclude" my node_modules under Settings -> Directories, my node_modules folder is red, and has Excluded selected, and it's not possible to unselect.

I can double shortcut for now, but is there a better resolution? Thanks!

34 comments
Comment actions Permalink

p.s. renaming the node_modules folder isn't a desirable solution, this is a large project with a lot of people, it's possible but would probably break a lot of scripts and such. Thanks.

0
Comment actions Permalink

I think that you can right click the node_modules directory -> Mark Directory As -> Cancel Exclusion. Maybe that would work?

 

0
Comment actions Permalink

Thanks Joey for the reply. Unfortunately they've removed "Mark Directory as" from the right click menu. "Remove BOM" is still there, but "Mark Directory as" previously just above it is now gone. There is an alternate way to do the same thing, under Settings -> Directories, but it's not possible to unselect `node_modules` as Excluded, it just won't let you do it.

0
Comment actions Permalink

I THINK I've seen a similar issue to this on one of my other projects. If you go to Languages & Frameworks -> Javascript -> Libraries  is node_modules in that list, and is it checked or unchecked?  My problem is that I couldn't exclude the node_modules because it WAS checked in that menu.  Maybe if you uncheck it as a library, you'll get that Mark Directory As option back?  I'm just throwing out ideas now, sorry.

 

 

0
Comment actions Permalink

Thank you Joey for the ideas. I took a look under Languages & Frameworks -> Javascript -> Libraries but no matter whether I made my node_modules directory checked or unchecked I couldn't bring back the "Mark Directory as" context menu option nor unselect it as Excluded under Settings -> Directories.

1
Comment actions Permalink

It sure does, thanks Andriy for the heads up! Doesn't look like there's a resolution yet but I posted there as well.

0
Comment actions Permalink

The forced exclusion is apparently an intentional change in 2016.2. 

I opened this support request (hopefully others can see it): https://intellij-support.jetbrains.com/hc/en-us/requests/746984?flash_digest=6872c6ef00a256fa4855279fef4fbacc3cbfd521&page=1

0
Comment actions Permalink

I can't see it, I get an "oops" error. But good luck! 

0
Comment actions Permalink

I'm having the same issue, too. Any feedback on this yet? Also, how do you know it was an intentional change? If it was, it wouldn't surprise me though. I think they should rename WebStorm to WebNanny.

0
Comment actions Permalink

Hi guys,

Yes, WebStorm 2016.2.2 handles all node_modules directories as npm-installed dependencies (thus, it's excluded automatically and marked as a library root). Sorry for the inconvenience.

The case when node_modules directory may contain application source code (not generated by `npm install`) will be addressed in WebStorm 2016.2.3 (see issue https://youtrack.jetbrains.com/issue/WEB-22909). The following logic is employed to determine whether node_modules directory contains application source code or not: a node_modules directory with a sibling package.json file is considered to contain npm-installed dependencies (it will be excluded automatically and marked as a library); without a sibling package.json - it's assumed to contain application source code.

Will this logic work for you? Thanks

1
Comment actions Permalink

Hi Sergey, yes, that logic will work great! Thank you!

0
Comment actions Permalink

Hello,

Why can't we just cancel automatic exclusion?

We use npm as our front dep injection system, thus all our own packages (named blocks in the screenshot) and external libs are located in a node_modules directory, directly linked in the index.html (../lib/node_modules/xxx/dist/xxx.js).

In order to use npm at full extent, we have a package.json located in that folder. Because we release and npm update our work on our private npm repsitory.

Now we can't use the code completion or research stuff in our own code anymore.

Thanks,

8
Comment actions Permalink

The bug/feature request to fix this is here:  https://youtrack.jetbrains.com/issue/WEB-23032

 

The temporary hack that was suggested to me to work around this is to create another directory in your project and link the actively developed packages there.  Works for me, but not ideal.

0
Comment actions Permalink

Just following up, I'm now using 2016.2.3 and it has solved my issues. It's nice to see how responsive JetBrains has been. Best of luck to all who still have issues.

0
Comment actions Permalink

Hi Simon,

Sorry for the late reply.

>Now we can't use the code completion or research stuff in our own code anymore.

Hmm, that's strange. The code completion should be available in node_modules. It'd be much appreciated if you could provide steps allowing to reproduce your problem. An artificial example project would be just great.

A small question about your project structure: IIUC, your own libraries are npm-installed from your private npm repository. Therefore, `node_modules/your-library/*`files are not under VCS and it shouldn't be modified manually after npm-installation, right?

Thanks

0
Comment actions Permalink

Thanks, Steve, for the update.Glad it works for you.

0
Comment actions Permalink

@ this is a problem for me.  I do not want node_modules forced as a library root, because it messes up the global find function.  I use the global find with custom scopes excluding node_modules.  But ... when node_modules is excluded it FORCES my custom scopes to search in node_modules, greatly slowing down search time.  :(    

0
Comment actions Permalink

Upgrading to 2016.2.3 fixed the problem for me.

0
Comment actions Permalink

Hi @,

I wasn't available until now, late reply for me too. :)

The problem still exists for us.

We decided to have two separate node_modules:

1. one at the root of the project for build related stuff (gulp etc.)
2. another into lib/node_modules with our own libraries as well as external front libraries (they all are linked into the index.html)

The second one, lib/node_modules is registered into git. Because we want everything to work all the time, even without network (as long as you have the sources, the project works). We also had bad experiences of external lib with same version number but different dist.
When we need to update our own libs (or an external one), the lead dev will npm update, check if everything is ok then commit and push for everyone to pull & use.

We separated the build related stuff and the front lib stuff because of the trillion files we can find in gulp and node modules. We didn't want that to pollute our git (we still have a .7zip package into git we pack and unpack because of lack of trust in the npm system).

Because of the fact node_modules is automatically excluded, it is excluded from global search and sometimes from autocomplete. Webstorm is now an obstacle for the dev: we have to manually search via scopes, or even remember the lib we want and open the file with shift+shift, look in the file and copy&paste the function name.

This is sad. :(

If you still need a sample project I can make one for you but it's difficult to justify the time to my hierarchy, we already had to argue in order for us to have licences for your products, they won't want to hear they slow us.

0
Comment actions Permalink

Hi Simon!

Thank a lot for the details! IIUC, there is no problem with node_modules at the root of the project. As for lib/node_modules, is there lib/package.json file? If yes, what dependencies/devDependencies does it have declared?

>The second one, lib/node_modules is registered into git.

Thanks, I see, npm is not used here at all. Thus, your project files and lib/node_modules/* files are tracked by the same git repository, right?

0
Comment actions Permalink

We have a package.json yes, because we need to update our own libs (in our private repository) as well as external libs. The lead dev will npm update into /libs then commit on git.

Everything is registered into dependencies, no devDependencies:
{
"name": "xxx",
"version": "0.1.0",
"description": "xxx",
"scripts": {},
"private": true,
"dependencies": {
"angular": "^1.5.0",
...
 }
}

Our project files and lib/node_modules/* are indeed in the same git repository. We still use npm as I said above, when we need to update a lib the lead dev will npm update and commit on git.

We have a dozen apps developped by several teams, we rely on npm because when one of our lib is updated (and released on our private repo) we just have to mail the lead devs, make them npm update and push and voilà, all the teams have the latest version of the lib.

--edit:
the root node_modules have no issues, it is used for build only and Webstorm behaves as expected (excluding it). It is not tracked into git (although we track a pack.7z).

0
Comment actions Permalink

Hi, Simon!

Thanks for the information and sorry for the late reply. Just noticed that your `lib/node_modules` folder is not marked as "library root" on your screenshot (https://intellij-support.jetbrains.com/hc/user_images/DkcAM2okaMFvV01hEYVd8Q.png). It means that the node_modules folder is simply excluded and direct dependencies (declared in lib/package.json under 'dependencies' key) are not indexed. 

Please open "Settings | Languages & Frameworks | JavaScript | Libraries" and locate "<relative path to>/lib/node_modules" library. Is it enabled? If no, just enable it. Will it bring expected code completion and navigation in your main application for modules imported from `lib/node_modules`?

You've described lifecycle of lib/node_modules updates in detail. Thanks for that. A small question regarding your original problem 

> Now we can't use the code completion or research stuff in our own code anymore.

In which files you don't have code completion: your main application or `lib/node_modules/*` files? If it's your main application (that doesn't include `lib/node_modules` IIUC) then enabling ".../lib/node_modules" should probably help.

0
Comment actions Permalink

Hello,

Sadly this is still not working.

I checked everything in the settings.


But sill no completion and search.



 

 

 

0
Comment actions Permalink

> In which files you don't have code completion: your main application or `lib/node_modules/*` files?

In my main application.

We don't code directly into the lib/node_modules, they are developped and npm released from another git repository.

They are into the project repository for convenience (at least they were, this is not really convenient anymore).

0
Comment actions Permalink

All right, thanks. Regarding your screenshot of "Find in Path" dialog, it's expected that "getFromState" is not found in the "Whole project" scope (which is the same as "Custom | Project files"). Since "getFromState" is defined in a file from "lib/node_modules" library, it should be found in "Custom | Project and Libraries" scope.

As for your second screenshot (not resolving of "CoreService.getFromState" method), is "blocks.core" package declared in `.../lib/package.json` under "dependencies" key?

BTW, what's your WebStorm version?

0
Comment actions Permalink

> Regarding your screenshot of "Find in Path" dialog, it's expected that "getFromState" is not found in the "Whole project" scope (which is the same as "Custom | Project files"). Since "getFromState" is defined in a file from "lib/node_modules" library, it should be found in "Custom | Project and Libraries" scope.

Ok I don't remember it was the case before but I can live with scopes. Thanks it will be easier to work already.

> As for your second screenshot (not resolving of "CoreService.getFromState" method), is "blocks.core" package declared in `.../lib/package.json` under "dependencies" key?

Yes.

{
"name": "xxx",
"version": "0.1.0",
"description": "xxx",
"scripts": {},
"private": true,
"dependencies": {
[...]
"blocks.core": "^3.0.0",
}

> version

WebStorm 2016.2.3
Build #WS-162.1812.21, built on September 4, 2016
Licensed to xxx / Simon Peyou
Subscription is active until xxx
JRE: 1.8.0_91-b15 amd64
JVM: Java HotSpot(TM) 64-Bit Server VM by Oracle Corporation

---

Here's a new information I just saw: we have 2 lib/node_modules in the project.
One for desktop app. One for mobile app. They both have different versions of same libs (as well as other unrelated libs)
Maybe the indexer got lost?



Thanks for your time, Sergey. Really appreciated. :)

0
Comment actions Permalink

Hmm, two "lib/node_modules" is hardly a problem.

Can the problem be reproduced for you locally if all needed files are copied to a new project:

* lib/node_modules/blocks.core/dist/blocks.core.js

* lib/package.json

* lib/app.js (which uses "CoreService.getFromState" from "blocks.core")

0
Comment actions Permalink

@Simon Peyou  Maybe it'd be better to move this particular discussion to a separate issue in our issue tracker (https://youtrack.jetbrains.com/issues/WEB#newissue) to avoid spamming others. ;)

0

Please sign in to leave a comment.