首頁  >  問答  >  主體

標題重寫為:預期的JavaScript模組腳本,但伺服器回應的MIME類型為text/html和text/css - 無框架,純JS

我正在嘗試使用顏色日曆,並且我正在按照他們在演示和文件中看到的教程進行操作,如下所示:

// js/calendar.js

import Calendar from '../node_modules/color-calendar';
import '../node_modules/color-calendar/dist/css/theme-glass.css';

let calA = new Calendar({
  id: "#color-calendar",
  theme: "glass",
  // border: "5px solid black",
  weekdayType: "long-upper",
  monthDisplayType: "long",
  // headerColor: "yellow",
  // headerBackgroundColor: "black",
  calendarSize: "small",
  layoutModifiers: ["month-left-align"],
  eventsData: [
    {
      id: 1,
      name: "French class",
      start: "2020-12-17T06:00:00",
      end: "2020-12-18T20:30:00"
    },
    {
      id: 2,
      name: "Blockchain 101",
      start: "2020-12-20T10:00:00",
      end: "2020-12-20T11:30:00"
    },
    {
      id: 3,
      name: "Cheese 101",
      start: "2020-12-01T10:00:00",
      end: "2020-12-02T11:30:00"
    },
    {
      id: 4,
      name: "Cheese 101",
      start: "2020-12-01T10:00:00",
      end: "2020-12-02T11:30:00"
    }
  ],
  dateChanged: (currentDate, events) => {
    console.log("date change", currentDate, events);
  },
  monthChanged: (currentDate, events) => {
    console.log("month change", currentDate, events);
  }
});

和我的 HTML:

// dashboard.html
...
<div class="col">
  <div class="calendar-container">
    <div id="color-calendar"></div>
    <div id="events-display"></div>
  </div>
</div>
...
<script type="module" src="js/calendar.js"></script>

我嘗試使用 http-server 和 Live Server 擴充功能來檢查它是否解決了問題,但問題仍然存在。

Failed to load module script: Expected a JavaScript module script but the server responded with a MIME type of "text/html". Strict MIME type checking is enforced for module scripts per HTML spec.

Failed to load module script: Expected a JavaScript module script but the server responded with a MIME type of "text/css". Strict MIME type checking is enforced for module scripts per HTML spec.

我在我的開發工具控制台上得到了這兩個

有關其他信息,這是我的 package.json

{
  "dependencies": {
    "color-calendar": "^1.0.7",
    "http-server": "^14.1.1"
  }
}

我不知道該怎麼辦了...沒有 Node.js,沒有框架,只是用 javascript、html 和 css。

P粉481035232P粉481035232331 天前779

全部回覆(1)我來回復

  • P粉254077747

    P粉2540777472023-11-23 15:34:52

    Konrad 和 Stefino76 帶來的解決方案奏效了。

    我在我的專案上安裝了 webpack 並將其配置為接受 .js 檔案中的 js 和 css,現在日曆可以正常工作了!

    所有的功勞都應該歸功於他們,但我認為我無法將他們的答案標記為已解決。

    回覆
    0
  • 取消回覆