Getting following error in Google chrome browser console for a Drupal project on localhost on Ubuntu system:

Refused to apply style from ****** because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled.

Any solution?

Comments

zaelo’s picture

Hello,

Is your css files correctly declared inside librairies.yml? Is your css folder reachable from within the server?

ramadan35’s picture

Check the css file if the first line a comment, try to remove the comments from the beginning of the file

sharmaraunak1998’s picture

Yes, First line was comment. I removed the comment>saved it>Cleared cache
But still showing the same error.

garikgelios’s picture

This problem was asked long ago, and one answer help me now.
I make git clone my Drupal 8 project on Windows from one local server (OSpanel) to another computer and get the same issue.
Hope this helps: https://www.drupal.org/project/jstools/issues/72561#comment-12566682

drush -y config-set system.performance css.preprocess 0
drush -y config-set system.performance js.preprocess 0

I do not fully understand what this strings do, but it helped me)

elfakhar’s picture

drush -y config-set system.performance css.preprocess 0
drush -y config-set system.performance js.preprocess 0

Thank you garikgelios 😊 

josip.rajkovic’s picture

Worked for me as well, thank you.

best-developer-drupal’s picture

drush -y config-set system.performance css.preprocess 0
drush -y config-set system.performance js.preprocess 0
aswathyajish’s picture

This worked for me.

nattyweb’s picture

Perfect - thanks @garikgelios. I'd replicated a site on a local dev machine and was seeing the same problem. 

axb’s picture

I was able to use these commands to get two copies of a Drupal site working. 

Initial condition was a stylesheet rendering error:

Refused to apply style from 'http://my-drupal-site.com/' because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled.

The page source code showed the stylesheet linked to "/", which resulted in the MIME type error:

<link rel="stylesheet" media="all" href="/" />

After running the drush command, the site loaded the theme stylesheet correctly:

drush -y config-set system.performance css.preprocess 0

As others mentioned - not sure why or how this solves the issue.

nestor_fabian’s picture

Gracias me funciono.

ldenna’s picture

It works with the drush preprocess commands, thank you!

jaimerod’s picture

Try fixing the permission on the temp folder defined in Configuration -> File System. 

Checking the logs should confirm that there is a problem writing to the folder: Reports -> Recent Log Messages

paulsally’s picture

On the staging server the temporary files directory /tmp/ had been set in settings.php to point inside /files/ but it had not been created.

This comment pointed me into the right direction. Thanks!

jaypan’s picture

Usually this error is reported when Drupal tries to load a .css file that does not exist. Because the file does not exist, the system returns a 'page not found' HTML page, which is text/html, and not text/css. So you need to determine why the .css file was not found - was the path incorrect? Was the file deleted?

Contact me to contract me for D7 -> D10/11 migrations.

davsev’s picture

It all worked until I installed panels module...
I tried to run the drush command advised above and clear cache but nothing changed.
I understand that ther may be a css file missing in panels module?
 

shobhit_juyal’s picture

where in my case, there is no css file name appears in the console. :(

Refused to apply style from 'http://localhost:88/' because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled.
jon_stewart’s picture

Jaypan, I'm one of the large number who have had to work hard to get to grips with Drupal 8 (after using it since 6).

So many problems I've come across, you've provided the right answer, or pointed in the right direction, so I just want to thank you for your continued contributions. It really helps.

Also, thanks to everybody else who shares their expertise.

Best regards
Jon

Jon

jaypan’s picture

And thanks for all the laughs John Stewart :)

But in all seriousness thanks for the kind comment. 

Contact me to contract me for D7 -> D10/11 migrations.

jon_stewart’s picture

My namesake is clearly a lot more amusing than me, but for every stupid programming mistake, there's a facepalm and a wry smile.

Have to see the funny side of everything, or we'd go mad!

Jon

jaypan’s picture

And thanks for all the laughs John Stewart :)

But in all seriousness thanks for the kind comment. 

Contact me to contract me for D7 -> D10/11 migrations.

jeevanm’s picture

+1

prabha1997’s picture

It's worked for me as well Thanks.

jorgemontoyab’s picture

Thanks Jaypan

gloomcheng’s picture

I'm facing same issue, it works with the drush preprocess commands, thank you!

pablo.fredes’s picture

sites/default/files should have 755 

chmod 755 sites/default/files

mchvdm’s picture

I had the same problem. I was rebuilding the site with composer and I had put my custom theme in the themes folder.

After moving it in the contrib folder (which is inside the theme folder) the problem was gone.

amagan’s picture

With the solutions offered above we modify the behavior of drupal, this way it will no longer preprocess the css and load them on each page so we will lose efficiency.

This error is usually related to the permissions in the FILES folder which is where drupal tries to preprocess the files to read them more efficiently. So assigning the correct permissions to files should work.

the_g_bomb’s picture

Please note that the drush commands listed above are not a solution, but a workaround

drush -y config-set system.performance css.preprocess 0

This command switches off aggregation of the css files, the js version of the above stops aggregation of the javascript files.

This solution makes your site slower, as it has to load more css and js files, and more weighty as the files are not minimised.

The solution is to debug errors in your css and js files, make sure the aggregation process can write to the files directory and that the file is being served properly.

The reason it works is that the unaggregated files load one after another and any errors in the files get skipped, that file doesn't load but the rest do. When aggregated the error causes the whole aggregated file to fail to load and nothing then loads as a result.

If you can find the one file or files causing the issue, your site will be far better off.

--
G

rpearl’s picture

I agree. The only reason this issue has ever popped up on me is when Drupal could not load the CSS/JS asset file correctly. Whether it be added versioning, incorrect filenames, or file access issues. Check your logs before doing anything further.

freddy rodriguez’s picture

Double check the yml definition.  In my case I was declaring the style as: css/mediaqueries  the correct way  is  css/mediaqueries.css   with the ,css ath the end.

mepperly’s picture

Bizarrely, the contrib theme I am using had .css on all of their other css files in the yml, but no .css on one of them. That was causing an error.

Also, our Drupal 9 sites with the same contrib theme aren't throwing an error, but the sites we have updated to Drupal 10 are.

In any case, I found your comment very helpful, @Freddy Rodriguez and wanted you to know.