Stylesheet not loaded because of MIME-type

前端 未结 30 2476
猫巷女王i
猫巷女王i 2020-11-22 07:29

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

The gulp task compiles everything

相关标签:
30条回答
  • 2020-11-22 08:06

    I was working with the React.js app 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 stylesheet:

    import 'path/to/stylesheet.css';
    
    0 讨论(0)
  • 2020-11-22 08:07

    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.

    0 讨论(0)
  • 2020-11-22 08:09

    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.

    0 讨论(0)
  • 2020-11-22 08:10

    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.

    0 讨论(0)
  • 2020-11-22 08:10

    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" >
    
    0 讨论(0)
  • 2020-11-22 08:14

    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.

    0 讨论(0)
提交回复
热议问题