[英]MIME type ('text/html') is not executable errors in Chrome
I am trying to add my webpack build.js file to my html page and I keep getting these 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: 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: 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 config: webpack配置:
const path = require('path')
module.exports = {
entry: './scripts.js',
output: {
path: __dirname + '/public',
filename: 'build.js'
},
watch: true
}
I have tried using the historyApiFallback: true
and it didn't fix anything. 我试过使用
historyApiFallback: true
,它没有解决任何问题。 I have read a lot about people fixing the issue in the HTML script tag being wrong, so maybe there is something I am not seeing. 我读过很多关于人们解决HTML脚本标签错误的问题的信息,所以也许有些事情我没有看到。 Hopefully someone can help me out!
希望有人可以帮助我! Thanks in advance.
提前致谢。
Just to clarify this is where my files are Main Folder: C:\\Users\\jake\\Documents\\project\\CoffeeClub\\newsletter 只是为了澄清这是我的文件所在的主文件夹: C:\\ Users \\ jake \\ Documents \\ project \\ CoffeeClub \\ newsletter
Inside Public I have these files: 在Public内部,我有以下文件:
You said: 你说:
app.use(express.static('public'));
So when the browser asks for /public/build.js
the server gives it ./public/public/build.js
. 因此,当浏览器要求输入
/public/build.js
,服务器会为其提供./public/public/build.js
。 Since that doesn't exist, it gives it a 404 instead. 由于该名称不存在,因此改为提供404。
One public from the URL, the other from the static base dir. 一个来自URL,另一个来自静态基目录。
If you want to include /public
in the URL, then you have to limit the route of the middleware. 如果要在URL中包含
/public
,则必须限制中间件的路由。
app.use('/public', express.static('public'));
在发现服务器拉出HTML的问题后,我删除了多余的public目录,并将其全部放在根目录中,并且现在可以正常工作了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.