IntelliJ/Webstorm not finding import reference
Question: I have the following project structure:

  * root 
    * src 
      * scripts 
        * main.js
        * foo.js

Inside of my `main.js` file, I'm importing `foo.js` like so:

    
    
    import 'src/scripts/foo.js'
    

When I click on the import statement above and go to `Navigate -> Declaration`
I get a super helpful message that says `Cannot find declaration to go`.

This makes it super frustrating to work with because the editor basically has
no idea which files import other files. This means I can't use the helpful
features of the IDE like _search for references_ when moving a file, find
usages, etc

If I change the import statement to be relative, it works altogether:

    
    
    import './foo.js'
    

However, we are striving for absolute imports, [a habit we picked up from
writing python apps](http://stackoverflow.com/questions/14132789/python-
relative-imports-for-the-billionth-time).

I came across [Webstorm: "Cannot Resolve
Directory"](http://stackoverflow.com/questions/21987225/webstorm-cannot-
resolve-directory) and that gave me the idea to `mark` my `src` directory as a
`Sources Root`. After doing that, I could change my import statement in
`main.js` to

    
    
    import '/scripts/foo.js' //notice the leading forward slash
    

Well, that's a little better because now I can at least `Navigate ->
Declaration` but it's not ideal because now I can't mark any of the
directories underneath `src` as a test, resource, etc.

So why is IntelliJ/webstorm making this so difficult to do?


Answer: > Because now I can't mark any of the directories underneath src as a test,
> resource, etc.

Yes, you can. It is not possible to mark subfolders of already marked folders
in the Project View. But you can do this in Project Structure (`Ctrl` \+
`Shift` \+ `Alt` \+ `S`). Go to `Modules`, select your module and switch to
the `Sources` tab. Now you can mark your `src` folder as `Sources` (which you
already did) and mark `src/test` as `Tests` etc.

According to the [Web
Help](https://www.jetbrains.com/webstorm/help/configuring-folders-within-a-
content-root.html), in WebStorm this setting is hidden in `Settings >
Directories` instead of the Project Structure.

Here's another solution using only the Project View: unmark your source
folder, mark your test/resource subfolders and then mark the (parent) source
folder again. I'm not sure, why it doesn't work the other way around.

