我有这个问题。Chrome继续返回此错误

资源解释为样式表,但以MIME类型text/html传输

受此错误影响的文件只有Style、chosen和jquery-gentleselect(以相同方式导入索引的其他CSS文件工作良好且没有错误)。我已经检查了我的MIME类型和文本/css已经在css上。

老实说,我想从理解问题开始(这似乎是我一个人做不到的事情)。


当前回答

如果你在prod中提供应用程序,请确保你在service worker中提供静态文件。当我在Django上只提供React构建的静态子文件夹时,我遇到了这个错误(没有具有样式的资产)

其他回答

In my case, same error was coming with JSP. This is how I got to the root of this issue: I went to the Network tab and clearly saw that the browser request to fetch the css was returning response header having "Content-type" : "text/html". I opened another tab and manually hit the request to fetch the css. It ended up returning a html log in form. Turns out that my web application had a url mapping for path = / Tomcat servlet entry : (@WebServlet({ "/, /index", }). So, any unmatching request URLs were somehow being matched to / and the corresponding servlet was returning a Log in html form. I fixed it by removing the mapping to /

此外,tomcat配置wrt处理css MIME-TYPE已经存在。

我也有这个错误的问题,并想出了一个解决方案。这并没有解释错误发生的原因,但似乎在某些情况下修复了它。

在css文件的路径前加上一个正斜杠/,如下所示:

<link rel=“stylesheet” href=“/css/bootstrap.min.css”>

我在MVC4中使用表单身份验证时遇到了类似的问题。问题出在web。config中的这一行,

<modules runAllManagedModulesForAllRequests="true">

这意味着每个请求,包括静态内容的请求,都要经过身份验证。

将这一行更改为:

<modules runAllManagedModulesForAllRequests="false">

当我从谷歌CDN提供的css样式表的css链接中删除协议时,就发生了这种情况。

这不会产生错误:

<link rel="stylesheet" href="//fonts.googleapis.com/css?family=Architects+Daughter">

但是这会给出错误资源解释为样式表,但传输MIME类型text/html:

<link rel="stylesheet" href="fonts.googleapis.com/css?family=Architects+Daughter">

我在为一个用npm安装的React布局模块加载CSS时遇到了这个问题。你必须导入两个.css文件来让这个模块运行,所以我最初导入它们是这样的:

@import "../../../../node_modules/react-grid-layout/css/styles.css";

但发现文件扩展名必须被删除,所以这是有效的:

@import "../../../../node_modules/react-grid-layout/css/styles";