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

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

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

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


当前回答

使用的反应

我在我的react profile应用程序中遇到了这个错误。我的应用程序表现得有点像它试图引用一个不存在的url。我相信这与webpack的行为有关。

如果你在公用文件夹中链接文件,你必须记住在资源之前使用%PUBLIC_URL%,就像这样:

<link type="text/css" rel="stylesheet" href="%PUBLIC_URL%/bootstrap.min.css" />

其他回答

我最近在chrome浏览器上也遇到了这个问题。我只是给我的CSS文件解决问题的绝对路径。

<link rel="stylesheet" href="<?=SS_URL?>arica/style.css" type="text/css" />

使用ReactJs,当我添加样式文件到index.html使用相对链接,如

<link rel="stylesheet" href="./css/style.css"> .

然后我导航到一条路线,说;localhost:3000/artist和刷新,我得到错误。

错误消失后,我取代相对链接与绝对链接说;

<link rel=“stylesheet” href=“http://localhost/project/public/css/style.css”。

试试这个<link rel="stylesheet" type="text/css" href="../##/yourcss.css">

哪里##是你的文件夹,其中是你的。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已经存在。

将匿名身份验证凭据设置为应用程序池标识对我来说很有用。