【问题标题】:reactjs Refused to apply style from 'bootstrap.min.css' because its MIME type ('text/html') is not a supported stylesheet MIME typereactjs 拒绝从“bootstrap.min.css”应用样式,因为它的 MIME 类型(“text/html”)不是受支持的样式表 MIME 类型
【发布时间】:2018-10-24 06:22:57
【问题描述】:

我正在制作一个 reactjs 网络应用程序,并想使用 react-bootstrap。 我的 index.html 看起来像:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Winova</title>
  <link rel="stylesheet" href="assets/styles/bootstrap.min.css">
<body>
  <section id="index"></section>
</body>
</html>

我得到的错误: 拒绝应用来自'http://localhost:8098/assets/styles/bootstrap.min.css' because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled.的样式

如果我像这样添加它,它会起作用:

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/latest/css/bootstrap.min.css">

问题是我不想依赖外部链接,我想在我的服务器上拥有自己的副本。

【问题讨论】:

标签: html css reactjs react-bootstrap


【解决方案1】:

回复较晚,但如果您来这里寻找答案,可以快速(可能)修复。

您使用的相对路径未正确指向文件。如果您查看控制台,您很可能会看到加载“已取消”,并且响应标头将是 mime 类型的 text/html,因此会出现错误消息。

尝试添加“./”以指向应用程序根目录。

href="./assets/styles/bootstrap.min.css"

在原始问题中提到的评论链接中有更多详细信息。

【讨论】:

    猜你喜欢
    • 2020-11-10
    • 2021-06-04
    • 1970-01-01
    • 2018-12-14
    • 1970-01-01
    • 2021-11-29
    • 1970-01-01
    • 2019-08-06
    • 2018-08-01
    相关资源
    最近更新 更多