764

I'm working on a website that uses Gulp.js to compile and browser sync to keep the browser synchronised with my changes.

The Gulp.js task compiles everything properly, but on the website, I'm unable to see any style, and the console shows this error message:

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

Now, I don't really understand why this happens.

The HTML includes the file like this (which I am pretty sure is correct):

<link rel="stylesheet" type="text/css" href="assets/styles/custom-style.css"/>

And the style sheet is a merge between Bootstrap and Font Awesome styles for now (nothing custom yet).

The path is correct as well, as this is the folder structure:

index.html
assets
|-styles
  |-custom-style.css

But I keep getting the error.

What could it be? Is this something (maybe a setting?) for gulp/browsersync maybe?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Nick
  • 13,493
  • 8
  • 51
  • 98
  • 250
    It happens when you set an incorrect URL to the file or when your server isn't configured properly. In the result, the browser DOESN'T get the stylesheet, but it gets some HTML with 404 status and with the "Content-Type" header. Since the browser gets something from the server, it doesn't tell you there is no reply, but it tells you the MIME type of the file is incorrect. The fastest way to check it is just to try to open the file directly `http://localhost:3000/assets/styles/custom-style.css` in a new tab. – RussCoder Sep 12 '18 at 07:08
  • In the currently 83 answers (incl. deleted), there are a lot of redundant answers (repeating previous answers). – Peter Mortensen Sep 29 '22 at 00:02

70 Answers70

297

For Node.js applications, check your configuration:

app.use(express.static(__dirname + '/public'));

Notice that /public does not have a forward slash at the end, so you will need to include it in your href option of your HTML:

href="/css/style.css">

If you did include a forward slash (/public/) then you can just do href="css/style.css".

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
JPaulino
  • 3,297
  • 1
  • 9
  • 7
  • This was my issue, even for javascript front end instead of Node backend... Starting with /css, the files were found. The error message is strangely bogus, implying it DID find the file and checked its type and found it to be wrong. – gwhiz Oct 03 '22 at 22:57
  • Isn't the different `href`s a matter of relative vs absolute URIs? Without a leading slash is relative to the page URL; with a leading slash is relative to the root (domain and port). As well as I remember in the middle of the night, anyway. I'm not too familiar with the specifics of `express.static()`, but I don't believe a trailing slash would make a difference? And if it does, what is the reason? – Darryl Noakes Jul 21 '23 at 05:51
188

The issue, I think, was with a CSS library starting with comments.

While in development, I do not minify files and I don't remove comments. This meant that the stylesheet started with some comments, causing it to be seen as something different from CSS.

Removing the library and putting it into a vendor file (which is ALWAYS minified without comments) solved the issue.

Again, I'm not 100% sure this is a fix, but it's still a win for me as it works as expected now.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Nick
  • 13,493
  • 8
  • 51
  • 98
  • In my case my css starts with comments, not causing any issues. The missing /css/ on the front of the path, where css/ was a folder at the root of the source tree, was my issue. – gwhiz Oct 03 '22 at 22:58
  • Yes, I don't have comments in one file and another has comments. Both have the same error. – netskink May 14 '23 at 15:27
179

In most cases, this could be simply the CSS file path is wrong. So the web server returns status: 404 with some Not Found content payload of html type.

The browser follows this (wrong) path from <link rel="stylesheet" ...> tag with the intention of applying CSS styles. But the returned content type contradicts so that it logs an error.

Enter image description here

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Tharaka
  • 2,883
  • 1
  • 21
  • 13
  • 15
    another way to troubleshoot, paste the url you're getting this error on into another tab, if you're not seeing CSS, this is likely the issue – BlackICE Dec 11 '19 at 16:20
145

This error can also come up when you're not referring to your CSS file properly.

For example, if your link tag is

<link rel="stylesheet" href="styles.css">

but your CSS file is named style.css (without the second s) then there is a good chance that you will see this error.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
John Deverall
  • 5,954
  • 3
  • 27
  • 37
  • 8
    To add to this answer, be sure gulp actually found the css file and piped it into your dist. Whenever I get this error, it is because I screwed up my path to the css files somehow and it just doesn't exist in the build directory. –  Jun 25 '18 at 19:37
72

I had this error for a Bootstrap template.

<link href="starter-template.css" rel="stylesheet">

Then I removed the rel="stylesheet" from the link, i.e.:

<link href="starter-template.css">

And everything works fine. Try this if you are using Bootstrap templates.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Amandeep Saini
  • 898
  • 7
  • 10
  • 12
    According to the [Living Standard (4.2.4)](https://html.spec.whatwg.org/multipage/semantics.html#attr-link-rel), *"A link element must have either a rel attribute or an itemprop attribute, but not both."* So, removing the `rel` attribute just removes the functionality of including a stylesheet. – Artjom B. Oct 17 '18 at 20:32
  • This worked for me too on bootstrap. Seems to stem from a different issue than what @nick was facing, but both issues return the same MIME error on console. – Darrow Hartman Mar 09 '23 at 17:06
68

I have changed my href to src. So from this:

<link rel="stylesheet" href="dist/photoswipe.css">

to this:

<link rel="stylesheet" src="dist/photoswipe.css">

It worked. I don't know why, but it did the job.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Sebastian Voráč MSc.
  • 3,256
  • 1
  • 18
  • 25
54

Make a folder just below/above the style.css file as per the Angular structure and provide a link like <link href="vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet">.

Enter image description here

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Gopi G.A
  • 589
  • 3
  • 4
  • 26
    Why does this work? The error states that "text/html" is not a supported MIME type. – James Bateson Mar 27 '18 at 11:15
  • 8
    In my case the error went away, the css styles, however, are not applied.. :/ – Andru Apr 19 '18 at 14:35
  • 3
    I did spend aome more time reading about this issue and changing the type of a css file ibto something else can cause serious issues, like css being read as html by the server – Nick Apr 20 '18 at 04:42
  • In AngularDart, the root for index.html is the 'web' folder not the project main folder. So all the css files must be inside the web folder. Like this "[projectfolder]\web\[yourcssfileshere]". So if you try to import a css file located outside the web folder it will not be found. – Wael Sep 02 '19 at 12:17
30

Comments in your file will trip this. Some minifiers will not remove comments.

Also

If you use Node.js and set your static files using express such as:

app.use(express.static(__dirname + '/public'));

You need to properly address the files.

In my case both were the issue, so I prefixed my CSS links with "/css/styles.css".

Example:

<link type="text/css" rel="stylesheet" href='/css/styles.css">

This solution is perfect as the path is the main issue for CSS not getting rendering

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
metal_jacke1
  • 405
  • 4
  • 10
28

In addition to using:

<base href="/">

Remove the rel="stylesheet" part from your CSS links:

<link type="text/css" href="assets/styles/custom-style.css"/>
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Murat Yıldız
  • 11,299
  • 6
  • 63
  • 63
22

I simply referenced the CSS file (an Angular theme in my case) in the styles section of my Angular 6 build configuration in angular.json:

Enter image description here

This does not answer the question, but it might be a suitable workaround, as it was for me.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
dvlsc
  • 542
  • 6
  • 14
19

I know it might be out of context but linking a non existed file might cause this issue as it happened to me before.

<!-- bootstrap grid -->
<link rel="stylesheet" href="./css/bootstrap-grid.css" />

If this file does not exist you will face that issue.

Safwat Fathi
  • 758
  • 9
  • 16
18

The problem is that if you have a relative path, and you navigate to a nested page, that would resolve to the wrong path:

<link rel="stylesheet" href='./index.css'>

so the simple solution was to remove the . since mine is a single-page application.

Like this:

<link rel="stylesheet" href='/index.css'>

so it always resolves to /index.css

There are a lot of answers to this question but none of them seem to really work. If you remove rel="stylesheet" it will stop the errors but won't apply the stylesheets.

The real solution:

Just remove the .. It works then.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Jared
  • 2,999
  • 1
  • 28
  • 39
18

As mentioned solutions in this post, some of the solutions worked for me, but CSS does not apply on the page.

Simply, I just moved the "css" directory into the "Assest/" directory and everything works fine.

<link rel="stylesheet" type="text/css" href="assets/css/bootstrap.css">
<link rel="stylesheet" type="text/css" href="assets/css/site.css" >
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Jitendra G2
  • 1,196
  • 7
  • 14
16

I got the same issue and then I checked that I wrote:

<base href="./"> in index.html

Then I changed to

<base href="/">

And then it worked fine.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
VIKAS KOHLI
  • 8,164
  • 4
  • 50
  • 61
15

Also for others using Angular-CLI and publishing to a sub-folder on the webserver, check this answer:

When you're deploying to a non-root path within a domain, you'll need to manually update the <base href="/"> tag in your dist/index.html.

In this case, you will need to update to <base href="/sub-folder/">

https://github.com/angular/angular-cli/issues/1080

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
simonberry
  • 910
  • 9
  • 20
13

I had this problem with a site I knew worked online when I moved it to localhost and PhpStorm.

This worked fine online:

<link rel="stylesheet" href="/css/additional.css">

But for localhost I needed to get rid of the slash:

<link rel="stylesheet" href="css/additional.css">

So I am reinforcing a few answers provided here already - it is likely to be a path or spelling mistake rather than any complicated server setup problem. The error in the console is a red herring; the network tab needs to be checked for the 404 first.

Among the answers provided here are a few solutions that are not correct. The addition of type="text/html" or changing href to src is not the answer.

If you want to have all of the attributes so it validates on the pickiest of validators and your IDE then the media value should be provided and the rel should be stylesheet, e.g.:

<link rel="stylesheet" href="css/additional.css" type="text/css" media="all">
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Henry's Cat
  • 796
  • 12
  • 9
10

I have had the same problem.

If your project's structure is like the following tree:

index.html
assets
|-styles
  |-custom-style.css
server
  |- server.js

I recommend to add the following piece of code in server.js:

var path = require('path')
var express = require('express')
var app = express()

app.use('/assets', express.static(path.join(__dirname, "../assets")));

Note: Path is a built-in Node.js module, so it doesn't need to install this package via npm.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Mostafa Ghadimi
  • 5,883
  • 8
  • 64
  • 102
9

You can open the Google Chrome tools, select the network tab, reload your page and find the file request of the CSS and look for what it have inside the file.

Maybe you did something wrong when you merged the two libraries in your file, including some characters or headers not properly for CSS?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
  • 1
    unfortunately i did try it but it is not really helping, the request fails instantly and it only has the request url (which is correct) – Nick Jan 14 '18 at 11:02
9

At times, this happens when the CSS file is not found. It's worth checking your base URL / path to the file.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
CodesmithX
  • 246
  • 4
  • 8
8

Adding to a long list of answers, this issue also happened to me because I did not realize the path was wrong from a browser-sync point of view.

Given this simple folder structure:

package.json
app
  |-index.html
  |-styles
          |-style.css

The href attribute inside <link> in file index.html has to be app/styles/style.css and not styles/style.css.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Stig Perez
  • 3,595
  • 4
  • 23
  • 36
8

In case you are using Express.js without any JavaScript code, try with:

app.use(express.static('public'));

As an example, my CSS file is at public/stylesheets/app.css.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Tal Hakmon
  • 475
  • 5
  • 6
7

For a Node.js application, just use this after importing all the required modules in your server file:

app.use(express.static("."));
  • express.static built-in middleware function in Express and this in your .html file: <link rel="stylesheet" href="style.css">
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
7

How I solved this. For Node.js applications, you need to set your **public** folder configuration.

// Express js
app.use(express.static(__dirname + '/public'));

Otherwise, you need to do like href="public/css/style.css".

<link href="public/assets/css/custom.css">
<script src="public/assets/js/scripts.js"></script>

Note: It will work for http://localhost:3000/public/assets/css/custom.css. But couldn't work after build. You need to set app.use(express.static(__dirname + '/public')); for Express

Shapon Pal
  • 1,098
  • 3
  • 16
  • 27
6

I was working with the React application and also had this error which led me here. This is what helped me.

Instead of adding <link> to the index.html, I added an import to the component where I need to use this style sheet:

import 'path/to/stylesheet.css';
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Alex Gongadze
  • 191
  • 1
  • 5
6

By going into my browsers console → Networkstyle.css ...clicked on it and it showed "cannot get /path/to/my/CSS", this told me my link was wrong. I changed that to the path of my CSS file.

The original path before change was localhost:3000/Example/public/style.css. Changing it to localhost:3000/style.css solved it.

If you are serving the file from app.use(express.static(path.join(__dirname, "public"))); or app.use(express.static("public")); your server would pass "that folder" to the browser so adding a "/yourCssName.css" link in your browser solves it

By adding other routes in your browser CSS link, you'd be telling the browser to search for the css in route specified.

In summary: Check where your browser CSS link points to.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
bahri noredine
  • 731
  • 9
  • 15
5

This is specific to TypeScript and Express.js

I Ctrl + F'd "TypeScript" and ".ts" and found nothing in these answers, so I'll add my solution here, since it was caused by (my inexperience with) TypeScript, and the solutions I've read don't explicit solve this particular issue.

The problem was that TypeScript was compiling my app.ts file into a JavaScript file in my project's dist directory, dist/app.js.

Here's my directory structure. See if you can spot the problem:

.
├── app.ts
├── dist
│   ├── app.js
│   ├── app.js.map
│   └── js
│       ├── dbclient.js
│       ├── dbclient.js.map
│       ├── mutators.js
│       └── mutators.js.map
├── public
│   ├── css
│   │   └── styles.css
├── tsconfig.json
├── tslint.json
└── views
    ├── index.hbs
    └── results.hbs

My problem is that in app.ts, I was telling express to set my public directory as /public, which would be a valid path if Node.js actually were running TypeScript. But Node.js is running the compiled JavaScript, app.js, which is in the dist directory.

So having app.ts pretend it's dist/app.js solved my problem. Thus, I fixed the problem in app.ts by changing

app.use(e.static(path.join(__dirname, "/public")));

to

app.use(e.static(path.join(__dirname, "../public")));
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
manbradcalf
  • 529
  • 5
  • 8
5

https://github.com/froala/angular-froala/issues/170#issuecomment-386117678 Found the above solution of adding

href="/">

Just before the style tag in index.html

enter image description here

Tadele Ayelegn
  • 4,126
  • 1
  • 35
  • 30
4

In my case, when I was deploying the package live, I had it out of the public HTML folder. It was for a reason.

But apparently a strict MIME type check has been activated, and I am not too sure if it's on my side or by the company I am hosting with.

But as soon as I moved the styling folder in the same directory as the index.php file I stopped getting the error, and styling was activated perfectly.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Jabulani
  • 76
  • 3
4

If you are setting Styles in JavaScript as:

    var cssLink = document.createElement("link");
    cssLink.href = "./content.component.scss";
    cssLink.rel = "stylesheet";

    /*  →  */   cssLink.type = "html/css";
    (iframe as HTMLIFrameElement).contentDocument.head.appendChild(cssLink);

Then just change field cssLint.type (denoted by the arrow in the above description) to "MIME":

   cssLink.type = "MIME";

It will help you to get rid of the error.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Shriram
  • 121
  • 2
  • 9
4

Bootstrap styles not loading #3411

https://github.com/angular/angular-cli/issues/3411

  1. I installed Bootstrap v. 3.3.7

    npm install bootstrap --save
    
  2. Then I added the needed script files to apps[0].scripts in the angular-cli.json file:

    "scripts": [
        "../node_modules/bootstrap/dist/js/bootstrap.js"
    ],
    
    // And the Bootstrap CSS to the apps[0].styles array
    
    "styles": [
        "styles.css",
        "../node_modules/bootstrap/dist/css/bootstrap.css"
    ],
    
  3. I restarted ng serve

It worked for me.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
hassan khademi
  • 1,156
  • 12
  • 14
4

If the browser can not find a related CSS file, it could give this error.

If you use an Angular application you do not have to use a CSS file path in file index.html:

<link href="xxx.css" rel="stylesheet"> 

You could use the related CSS file path in the styles.css file.

@import "../node_modules/material-design-icons-iconfont/dist/material-design-icons.css";
Ahmet Arslan
  • 5,380
  • 2
  • 33
  • 35
3

One of the main reasons for the issue is the CSS file, which it is trying to load, isn't a valid CSS file.

Causes:

  • Invalid MIME type
  • Having JavaScript code inside style sheet - (may occur due to incorrect Webpack bundler configuration)

Check the file which you're trying to load is a valid CSS style sheet (get the server URL of the file from the network tab and hit in a new tab and verify).

Useful info for consideration when using <link> inside the body tag.

Though having a link tag inside the body is not the standard way to use the tag. But we can use it for page optimization (more information: Optimize CSS Delivery) / if the business use case demands (when you serve the body of the content and server configured to have to render the HTML page with content provided).

While keeping inside the body tag we have to add the attribute itemProperty in the link tag like

<body>
    <!-- … -->
      <link itemprop="url" href="http://en.wikipedia.org/wiki/The_Catcher_in_the_Rye" />
    <!-- … -->
</body>

For more information on itemProperty, have a look in Can I use <link> tags in the body of an HTML document?.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
BALA
  • 188
  • 1
  • 12
3

Remove rel="stylesheet" and add type="text/html". So it will look like this -

<link href="styles.css" type="text/html" />
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
3

This issue happens when you're using a command-line tool for either React or Angular, so the key is to copy the entire final build from those tools since they initialize their own light servers which confuses your URLs with the back end server you've created...

Take that whole build folder and dump it on the asset folder of your back end server project and reference them from your back end server and not the server which ships with Angular or React. Otherwise, you're using it as the front end from a certain API server.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
ndotie
  • 1,830
  • 17
  • 18
3

In my case I had to both make sure that the link was relative and the rel property was after the href property:

<link href="/assets/styles/iframe.css" rel="stylesheet">    
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
David Jarrin
  • 1,635
  • 4
  • 19
  • 40
3

I also had the same problem: here is the solution. Don't write public in path of the CSS link in your .html file. Although your .css file present in the public folder.

Example:

JavaScript file

app.use(express.static("public"));

HTML file

Use this

<link href="styles.css" rel="stylesheet">

instead of

<link href="index/styles.css" rel="stylesheet">
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
veer vikram
  • 111
  • 1
  • 4
3

I was facing the same issue in EJS and Node.js.

I have set up my view engine's public folder like this:

app.use('/public', express.static(process.cwd() + '/public'));

app.set('view engine', 'ejs');

And my directory structure was like this

public
|
-assets
 |
  --CSS
  |---style.css

I was trying to link my Style.css in EJS head like this

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

Adding the public solved the problem (make sure to check network tab)

<link href="/public/assets/css/style.css" rel="stylesheet" type="text/css">
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Saad Abbasi
  • 745
  • 11
  • 25
2

The solution from this thread solved my problem:

Not sure if this will help anyone, but if you are using angular-cli, I fixed this by removing the CSS reference from my index.html and adding it to the angular-cli.json file under the "style" portion. After restarting my webserver I no longer had that issue.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
newbie
  • 1,157
  • 2
  • 9
  • 17
2

I came across this issue having the same problem adding a custom look and feel to an Azure B2C user flow. I found that the root that the HTML page referred to was ../oauth/v2 (i.e. the OAuth server path) rather than the path to my storage bob.

Using the full URL of the pages fixed the problem for me.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Liam
  • 5,033
  • 2
  • 30
  • 39
2

Check if you have a compression enabled or disabled. If you use it or someone enabled it, then app.use(express.static(xxx)) won't help. Make sure your server allows for compression.

I started to see the similar error when I added Brotli and Compression Plugins to my Webpack. Then your server needs to support this type of content compression too.

If you are using Express.js then the following should help:

app.use(url, expressStaticGzip(dir, gzipOptions)

Module is called: express-static-gzip

My settings are:

const gzipOptions = {
  enableBrotli: true,
  customCompressions: [{
  encodingName: 'deflate',
  fileExtension: 'zz'
 }],
 orderPreference: ['br']
}
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Greg Wozniak
  • 5,209
  • 3
  • 26
  • 29
2

Nothing that everyone comments has helped me, the solution has been to fix the routes since from the main page I found the file but when I navigated it disappeared, the correct solution would say to have these things well placed

enter image description here

enter image description here

elver
  • 103
  • 1
  • 9
2

Add Express.js default static middleware as:

Import express const express = require("express")

Initialize express const app = express()

app.use(express.static(__dirname));

Then you need to use complete path of public directory

For example:

Your file structure inside public directory

public > css > style.css

Your path will be

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

Note 1:

You can use any name instead of public, i.e., assets myassets any other.

Note 2: your server should be running in the main directory. If your server is running in a sub directory, then you can come out by using ../

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
2

It's the path that is wrong.

My path was

href="public/css/style.css".  <!-- But it should be href="public/style.css" -->

And it didn't work. I tried all other ways, but still it did not work. So I copied the relative path, changed the backslash to forward slash, and then it started to work.

If you're not sure of the path, right click the style.css file, click "Copy Relative Path", and then paste it into

  href="public\style.css"

You just need to change the backward slash to a forward slash.

  href="public/style.css"

Enter image description here

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
William Hou
  • 1,251
  • 14
  • 17
1

Triple check the name and path of the file. In my case I had something like this content in the target folder:

lib
    foobar.bundle.js
    foobr.css

And this link:

<link rel="stylesheet" href="lib/foobar.css">

I guess that the browser was trying to load the JavaScript file and complaining about its MIME type instead of giving me a file not found error.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
pasx
  • 2,718
  • 1
  • 34
  • 26
1

I had this error, in Angular. The way I solved it was to put an ngIf on my link element, so it didn't appear in the DOM until my dynamic URL was populated.

It may be unrelated to the question a little bit, but I ended up here looking for an answer.

<link *ngIf="cssUrl" rel="stylesheet" type="text/css" [href]="sanitizer.bypassSecurityTrustResourceUrl(cssUrl)">
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
SeanMC
  • 1,960
  • 1
  • 22
  • 33
1

I met this issue.

I refused to apply the style from 'http://m.b2b-v2-pre1.jcloudec.com/mobile-dynamic-load-component-view/resource/js/resource/js/need/layer.css?2.0' because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled.

Changing the path could solve this issue.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
ZILONG PAN
  • 6,305
  • 1
  • 11
  • 6
1

I had the same problem, and in my case it was due to the fact that I had manually tried to import (s)CSS files in the HTML file (like we always do with static websites), when in fact the files had to be imported in the entry point JavaScript file used by Webpack.

When the stylesheets were imported into the main JavaScript file, rather than manually written in the HTML, it all worked as expected.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Magnus
  • 6,791
  • 8
  • 53
  • 84
1

Maybe you have an authorization issue with Buddy:

Try these steps:

  1. Go to ISS → find your project listed → click on it → Click on Edit permissions in the right pane under actions
  2. You will see your project properties wizard. Click on Securities
  3. Under groups or user names → If you see 'Authenticated users', then you are authorized if not then you have to it.
  4. Once you add it (yourself or with the help of your administrator if you work in a company :)), the website will start loading resources. You may need to restart your project under ISS.
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
YogiAR
  • 2,207
  • 23
  • 44
1

Yet another reason for this error may be that the CSS file permissions are incorrect. In my case the file was inaccessible because ownership had been changed to the root user-- which happened due to pushing Git files as the root user.

apostl3pol
  • 874
  • 8
  • 15
1

In my case it was the execution order of tasks ran by Grunt.

It was executing the task connect that sets up the local server and automatically opens the application in a new tab before executing less and postcss that transpile styles.

Basically, I changed this:

grunt.registerTask('default', 'Start server. Process styles.', ['connect', 'less', 'postcss']);

To this:

grunt.registerTask('default', 'Process styles. Start server.', ['less', 'postcss', 'connect']);

And it worked!

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Consta Gorgan
  • 549
  • 6
  • 22
1

I faced a similar error and found that the error was adding '/' at the end of the style.css link href.

Replacing <link rel="stylesheet" href="style.css/"> with <link rel="stylesheet" href="style.css"> fixed the issue.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Gladiator
  • 85
  • 1
  • 14
1

In case you're working with a Node.js application, make sure that the \public folder is immediately below the root folder, and not within the views folder.

This can become troublesome. Move the \public immediately below the root and then restart the server and witness the changes.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
taurus05
  • 2,491
  • 15
  • 28
1

I almost tried all given solutions. The problem for me was I didn't have any MIME types option in IIS, that is, I was missing this Windows feature.

The solution for me was:

"And if you're on a non-server OS like Windows 8 or 10, do a search on the start page for "Turn Windows features on or off" and enable: Internet Information Services -> World Wide Web Services -> Common HTTP Features -> Static Content"

Enable IIS Static Content

Enable IIS Static Content

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Sayyed Dawood
  • 607
  • 7
  • 15
1

I was facing the same problem.

I change my directories' permission to 755 ((U)ser / owner can read, can write and can execute. (G)roup can read, can't write and can execute. (O)thers can read, can't write and can execute.) and now all the files are loading.

You can also try my answer. I hope this will work for you.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Adnan Ahmad
  • 848
  • 1
  • 13
  • 12
1

I faced this challenge with Select2. It got resolved after I downloaded the latest version of the library and replaced the one (the CSS and JavaScript files) in my project.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Yaw
  • 156
  • 1
  • 4
1

In my case the problem was solved just after changing the random value in the .scss file. After reloading the problem disappeared and the styles began to load well. Simple, but works :P

borkson
  • 43
  • 4
1

I have used a virtual domain in my XAMPP installation and got this issue. So in the httpd-vshosts.conf file when I checked, I had explicitly pointed to the index.php file and this had caused the issue.

So I changed this:

<VirtualHost *:80>
    DocumentRoot "C:/xampp/htdocs/cv/index.php"
    ServerName cv.dv
</VirtualHost>

to this:

<VirtualHost *:80>
    DocumentRoot "C:/xampp/htdocs/cv/"
    ServerName cv.dv
</VirtualHost>

And then the files were loaded without issues.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Ahmad Karimi
  • 1,285
  • 2
  • 15
  • 26
1

In my Angular-Ionic project I've a CSS entry like this for a component which would only load when I request.

 .searchBar {
    // --placeholder-color: white;
    // --color: white;
    // --icon-color: white;
    // --border-radius: 20px;
    // --background: color:rgba(73,76,67,1.0);
    // --placeholder-opacity: 100%;
    // background-color: red;
  }

As soon as I commented out all the values inside the CSS class entry, it started working again.

I think this was happening due to having these properties background-color with --background together.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Hemang
  • 26,840
  • 19
  • 119
  • 186
  • `//` is not a valid comment character sequence in CSS (only the C-style one is, `/* */`). This is also indicated by the weird syntax highlighting here. It *will* break in some browsers (e.g., it may ignore all or part of the rest of the CSS (terminate parsing)). – Peter Mortensen Sep 28 '22 at 23:08
1

I would like this share some thoughts on this topic, when I place

app.use(expres.static('../frontEnd/public'))

it don't work, but when I use

app.use(express.static('/frontEnd/public'))

it works fine.

cottontail
  • 10,268
  • 18
  • 50
  • 51
1

Please also check for typos in your filename. This happened to me:

style.css.css
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
0

I had the same problem and after hours of debugging I found out that it is related to temporary files not able to be written.

Go to AdminConfigFile system. Set the correct temporary directory. Make sure your server has permission to write to that directory.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Asit
  • 458
  • 4
  • 14
0

Resaving a .ts file (forcing Ionic to rebuild) solved it for me.

It doesn't really make sense... but as long as it works, who am I to judge?

Here I have seen this workaround: Ionic and Angular 2 - Refused to apply style from 'http://localhost:8100/build/main.css' because its MIME type ('text/html') is not a supported

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
luciomonter
  • 338
  • 5
  • 7
0

I tried to restart my Windows machine and reinstalled the "npm i".

It worked for me.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
verma
  • 57
  • 4
0

Faced the similar issue and solved it using this simple fix. If your project is React based then instead of importing your "styles.css" in "index.html", import it in "index.js" which generally resides inside "src" folder of your project. This will make sure that all your routes inside your React Application has access to the styles file.

Dharman
  • 30,962
  • 25
  • 85
  • 135
Klaus
  • 13
  • 4
0

One solution that worked for me was changing the CSS filename from "style.css" to another name, like "component.css". It worked like a charm.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Emilio Grisolía
  • 1,183
  • 1
  • 9
  • 16
0

Another cause can be the two Apache .conf files, where, if your configuration forces HTTPS, then your server will overlook variables set in your sites-enabled/http-default.conf. For example, if you have "/static" defined in http-default.conf, but not https-ssl.conf then your static files may not get found, i.e., 404.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
C. Cosse
  • 51
  • 4
0

The path was different for localhost and while accessible via file:// & when deployed...

Daniel Danielecki
  • 8,508
  • 6
  • 68
  • 94
-1

For Node.js users, use this. This should solve the problem for Node.js.

app.use(express.static('static'));

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Mbonu Chinedu
  • 24
  • 1
  • 3
-1

Adding <base href="/"> in public/index.html in my React application solved the issue for me as well.

solved

Eunit
  • 107
  • 1
  • 3
  • What is the theory behind it? Why does it work? Please respond by [editing (changing) your answer](https://stackoverflow.com/posts/74788082/edit), not here in comments (but ***** ***** ***** ***** ***** ***** ***without*** ***** ***** ***** ***** ***** ***** "Edit:", "Update:", or similar - the answer should appear as if it was written today). – Peter Mortensen Mar 22 '23 at 21:36
-6

You must have imported multiple style sheets. Try to remove one and try again.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131