tchiot.ludo
tchiot.ludo

Reputation: 1004

How to mark a directory as library root?

I've 2 projects in PhpStorm: one is working well while another won't work and I can't figure what make the first one working.

The first one is working well with library root for bower, npm and composer :

enter image description here

The second one is bower, npm are not detected as library root : enter image description here

So the behaviour in PhpStorm is different, when I use the navigate file on second project, I see all the vendor file by default :

enter image description here

If I mark the directory as excluded, the ide don't understand the vendor class : enter image description here

So how can we configure the IDE to mark a directory as library root ?

Upvotes: 35

Views: 19589

Answers (4)

I.G. Pascual
I.G. Pascual

Reputation: 5965

Option 1

Go to File > Project Structure

Go to Project Settings > Modules and remove the library folder (i.e. /node_modules) from both the Excluded folders and Content root sections.

Content root library folder and excluded folder node_nodules

Your project structure will look like this:

Last, restart IntelliJ.

Option 2

Go to your project IntelliJ file <your-project>.iml found on the root folder and remove the lines containing the library path (using /node_modules as example):

<?xml version="1.0" encoding="UTF-8"?>
<module type="WEB_MODULE" version="4">
  <component name="NewModuleRootManager" inherit-compiler-output="true">
    <exclude-output />
    <content url="file://$MODULE_DIR$">
      <excludeFolder url="file://$MODULE_DIR$/dist" />
      <excludeFolder url="file://$MODULE_DIR$/node_modules" />
    </content>
    <content url="file://$MODULE_DIR$/node_modules" />
    <orderEntry type="inheritedJdk" />
    <orderEntry type="sourceFolder" forTests="false" />
  </component>
</module>

Your project structure should go back to normal.

Upvotes: 1

Tranzium
Tranzium

Reputation: 103

  • File > Settings > Directories
  • Remove any node_modules entries (right-hand side, x's)

Thank you to @Allisone for providing the manual solution.

Based on their response, I was able to replicate the solution using the settings.

Upvotes: 7

Allisone
Allisone

Reputation: 9054

Found a solution that worked for me.

I opened the .idea folder (in sublime), searched all files for the text node_modules and removed the lines containing it.

In my case I had 2 entries

  • workspace.xml

<property name="ts.external.directory.path" value="$PROJECT_DIR$/node_modules/typescript/lib" />

  • project-name.iml

<content url="file://$MODULE_DIR$/node_modules" />

Now my node_modules directory is automatically marked as library root again

Upvotes: 10

tchiot.ludo
tchiot.ludo

Reputation: 1004

Thanks to @LazyOne comment, found the solution : Select Preferences | Languages & Frameworks | JavaScript | Libraries and click Add. Select the path you want to add and the folder will be marked as library root. Really useful for non standard path (not bower_components for example)

Upvotes: 30

Related Questions