Webstorm: "Cannot Resolve Directory"

JavascriptHtmlAngularjsIdeWebstorm

Javascript Problem Overview


This is starting to bug me and I'd either like it turned off or fixed. So Webstorm has a sweet feature in it's HTML parser that will attempt to resolve directories in strings that are supposed to reference a file in your project. For example:

two examples

Webstorm is correct. My front end code is all in /app but my server serves up files in app on the root, so in the web context /app is actually just /. As a side, this behavior also impacts my angular templates:

webstorm hates angular directive templateUrl

and my angular-ui routes (I imagine it would do that for regular angular routes as well).

webstorm hates angular routes templateUrl

Is there a way that I can change webstorm to treat /app as the root so this is a useful feature? If not, is there a way I can disable this? I tried going into the inspector, but couldn't find an option for it:

webstorm inspector

And no, it's not the XML one... I tried.

Help appreciated. Thanks...

Javascript Solutions


Solution 1 - Javascript

To make file references to a non-root folder in your project, you'll need to mark that directory as a Resource. To do this, go to Settings > Directories and select your asset root folder from the right-hand panel. Then mark it as Resource Root by clicking the button above the file browser.

From the Jetbrains documentation, a Resource Root enables WebStorm to complete relative paths to resources under the selected folder. This means that you should use Resource Root on a folder that holds all the resources you would like to refer to (e.g. styles, scripts, ...).

Solution 2 - Javascript

I had this problem on Mac and solved it by changing the directories properties.

  1. Open Preferences:

Webstorm > Preferences

  1. Go to Directories section in the Preferences

Project > Directories

  1. Add content root and Resource roots

Screenshot after adding the resources root

Solution 3 - Javascript

for people using IntelliJ Ultimate:

enter image description here

Solution 4 - Javascript

I think this is what most people are looking for: not changing the content root, but adding a sub-folder as 'Resource Root'.

enter image description here

Solution 5 - Javascript

In Jet Brains WebStorm Go to File-->Settings-->Left Panel Select Project-->Click on Derectories-->Middle Panel Select Resource Root-->add the folders/Directories under your Project for reference or In the Right Panel You Can see +Add Content Root choose the directories and the Apply-->OK

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionkentcdoddsView Question on Stackoverflow
Solution 1 - JavascriptthomastutsView Answer on Stackoverflow
Solution 2 - JavascriptgeckobView Answer on Stackoverflow
Solution 3 - JavascriptJoachimRView Answer on Stackoverflow
Solution 4 - JavascriptViBoNaCciView Answer on Stackoverflow
Solution 5 - JavascriptNitesh DashView Answer on Stackoverflow