[英]loading a bundle.js file from webpack changes mime type to text/html
我正在嘗試使用react-redux和express為服務器實現服務器端渲染,webpack用於創建捆綁包。
我開始使用以下文檔:
https://redux.js.org/docs/recipes/ServerRendering.html
我有以下設置來加載從webpack創建的main.js:
<script type="application/javascript" src="/static/main.js"></script>
在啟動快速服務器時,這是我在控制台中看到的:
Refused to execute script from 'http://localhost:8080/static/main.js' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled.
這不會在任何瀏覽器中啟動。 知道可能會發生什么嗎?
在我看來,這是配置問題。
如果它返回MIME type ('text/html')
,這意味着,在該特定路徑上它無法找到/解析main.js
文件,因此它返回一個默認的404 html頁面,嚴格定義為是javascript。
因此,理想情況下,您可以將快速服務器配置為提供靜態文件,如下所示。
app.use(express.static(__dirname + "/static"));
有關更多詳細信息,請參閱:: - > https://expressjs.com/en/starter/static-files.html
快樂的編碼!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.