0

I created a blank project in Webstorm (2018.3) and created the following file structure:

.
+--css
|  +--style.css
+--view
   +--index.html

I then added this code to the head of index.html:

<link rel="stylesheet" type="text/css" href="/src/css/style.css">

Now code inspection feels that this is correct, and indeed that is the path from the project root. However Webstorm will not serve style.css from this path, presenting MIME validation errors if I attempt to use it.

Refused to apply style from 'http://localhost:63342/src/css/style.css' because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled.

I did some digging into the built-in server for WebStorm which revealed that it includes the project name as part of the root path. I adjusted the path to style.css and sure enough, this worked /JS-Tip/css/style.css. However this causes the code inspector to complain that it can't resolve the path.

Looking into this problem led me to this question Webstorm: "Cannot Resolve Directory". So I added src/ as a resource root, but I was still unable to use it in the path. So I tried setting the project root Js-Tip/ as a resource root but it did not resolve the inspection warning. I even tried adding both JS-Tip/ and src/ as resource roots and it changed nothing, not even when using JS-Tip/src/css/style.css as the path.

So my question is, how do I resolve this warning? Or, barring that, how do I get the server to accept src/ as an acceptable root for the file path?

1 Answer 1

1

You have a leading slash in your URL (<link rel="stylesheet" type="text/css" href="/src/css/style.css">) - note the leading / before src. Such slashes tell the browser to resolve URLs from the web server root. But the built-in web server serves files from http://localhost:63342/<project name>, so no resources can be loaded from http://localhost:63342 - thus 404 errors are thrown.

To work out the issue, change URLs to the ones relative to current .html file - like href="../css/style.css"

1
  • That's it precisely! Thank you, can't believe I overlooked that. Guess that's what happens when you spend all your time in a CMS.
    – Lord Drake
    Feb 20, 2019 at 16:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.