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

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

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

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


当前回答

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

更多信息:

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

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

其他回答

我在恢复一个旧的MEAN堆栈项目时遇到了同样的问题。我使用nodemon作为我的本地开发服务器,得到了相同的错误资源解释为样式表,但使用MIME类型text/html传输。我从nodemon更改为http-server,可以在这里找到。它立刻对我起了作用。

这是因为您必须将内容类型设置为文本/html而不是文本/css为您的服务器页面(php,node.js等)

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

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

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

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

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

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

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