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

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

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

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


当前回答

我也面临着同样的问题。在做了一些研究之后,我发现问题出在文件名上。实际文件的名称是“lightgaly .css”,但在链接时我输入了“lightgaly .css”。

更多信息:

它在我的本地主机上运行良好(操作系统:Windows 8.1 &服务器:Apache)。 但是当我将我的应用程序上传到远程服务器(与我的本地主机不同的操作系统和Web服务器)时,它不起作用,给了我和你一样的错误。

因此,问题是服务器的大小写敏感性(与文件名有关)。

其他回答

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已经存在。

我想扩展Todd R在op中的观点。在asp.net页面中,web。配置文件定义访问应用程序中每个文件或文件夹所需的权限。在我们的例子中,CSS文件文件夹不允许未经授权的用户访问,导致它在用户获得授权之前在登录页面上失败。更改web中所需的权限。通过修改CSS文件配置,可以防止非法用户访问CSS文件,解决了这一问题。

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

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

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

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

以防有人来到这个帖子,有类似的问题。我也遇到过类似的问题,但是解决方法很简单。

一名开发人员错误地丢失了一份网页副本。将config文件放到CSS目录下。删除后,所有错误都得到解决,页面正常显示。

如果nodejs和使用express 下面的代码工作…

res.set('Content-Type', 'text/css');