![](/img/trans.png)
[英]Webpack on Express MIME type ('text/html') is not executable
[英]MIME type ('text/html') is not executable errors in Chrome
我正在嘗試將webpack build.js文件添加到我的html頁面中,並且在Chrome中不斷收到這些錯誤:
GET http://localhost:3000/public/build.js net::ERR_ABORTED 404 (Not Found)
Refused to execute script from 'http://localhost:3000/public/build.js' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled.
app.js:
const express = require('express');
const app = express();
app.use(express.static('public'));
app.listen(3000, function() {
console.log('poopy');
});
app.post('/', function(req, res) {
res.end('success');
});
index.html的:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Coffee Newsletter</title>
</head>
<body>
<form action="/" method="post">
<input type="email" name="email">
<input type="submit" name="submit">
</form>
<script type="text/javascript" src="./public/build.js"></script>
</body>
</html>
webpack配置:
const path = require('path')
module.exports = {
entry: './scripts.js',
output: {
path: __dirname + '/public',
filename: 'build.js'
},
watch: true
}
我試過使用historyApiFallback: true
,它沒有解決任何問題。 我讀過很多關於人們解決HTML腳本標簽錯誤的問題的信息,所以也許有些事情我沒有看到。 希望有人可以幫助我! 提前致謝。
只是為了澄清這是我的文件所在的主文件夾: C:\\ Users \\ jake \\ Documents \\ project \\ CoffeeClub \\ newsletter
在Public內部,我有以下文件:
你說:
app.use(express.static('public'));
因此,當瀏覽器要求輸入/public/build.js
,服務器會為其提供./public/public/build.js
。 由於該名稱不存在,因此改為提供404。
一個來自URL,另一個來自靜態基目錄。
如果要在URL中包含/public
,則必須限制中間件的路由。
app.use('/public', express.static('public'));
在發現服務器拉出HTML的問題后,我刪除了多余的public目錄,並將其全部放在根目錄中,並且現在可以正常工作了。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.