Mark node_modules folder as library root after exclusion
Hi,
I would like some assistance regarding the node_modules setup in IntelliJ idea Ultimate.
I have a polyglot project that is based on Gradle. We have some java modules and some js modules.
For performance reason, we decided to exclude the node_modules directory using the idea gradle plugin.
This obviously disable the auto-completion for javascript libraries, so a workaround was to use JavaScript | Libraries to configure some of the core libraries. However, with more and more libraries being written in typescript or having their typing definitions inside the library itself, this does not work.
According to configuring-javascript-libraries, IntelliJ should automatically mark node_modules directories as excluded and configure them as libraries.
I have setup an example polyglot project and this does work (i.e. the node_modules is marked as library root by default)

However, if I decide to mark the node_modules directory as not excluded, I don't find a way to mark it as library root again.


Can you give me some directions on how I could do this? Is there a way to do this with the gradle idea plugin?
I have also filed a ticket here: https://youtrack.jetbrains.com/issue/IDEA-254213
Here is a toy project where you should be able to reproduce this behavior:
Upload id: 2020_11_07_MoyAMhJDK9JtULLv (file: polyglot-example.zip)
----
I don't understand where these settings are stored.
Here are the several things I have tried:
- removing the node_modules folder, restarting IntelliJ
- looking for differences in the .idea folder when the project has recognized the node_modules folder as library root vs when it did not
- looking in /Library/Application Support/JetBrains/IntelliJIdea2020.2/options/applicationLibaries.xml
Thanks
Please sign in to leave a comment.
- Mark directory as | Cancel exclusion
- in Project structure | Modules, remove
js-app/node_modulesfrom additional content rootsThank for your answer! It works perfectly.
Any advice on how to achieve the same in PhpStorm 2023.2? I cannot find "Project structure | Modules" anywhere — has it been renamed?
UPD: Found it, it is now named "Directories", and the content root "node_modules" (in gray) was very difficult to find among the long list lists of Test Source Folders (green) and Excluded Folders (screaming red), but after triple-checking it, I was able to find it. Problem solved.