简体   繁体   English

MIME类型('text / html')不是Chrome中的可执行错误

[英]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

  • Public 上市
  • app.js app.js
  • scripts.js scripts.js中
  • webpack.config.js webpack.config.js

Inside Public I have these files: 在Public内部,我有以下文件:

  • build.js build.js
  • index.html 的index.html

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.

相关问题 Express MIME 类型 ('text/html') 上的 Webpack 不可执行 - Webpack on Express MIME type ('text/html') is not executable javascript:MIME类型(&#39;text / html&#39;)无法执行,并且启用了严格的MIME类型检查 - javascript: MIME type ('text/html') is not executable, and strict MIME type checking is enabled 拒绝执行脚本,因为 MIME 类型('text/html')不可执行,并且启用了严格的 MIME 类型检查 - Refused to execute script because MIME type ('text/html') is not executable, and strict MIME type checking is enabled Dropbox:MIME 类型 (&#39;text/html&#39;) 不可执行,并且启用了严格的 MIME 类型 &gt; 检查 - Dropbox: MIME type ('text/html') is not executable, and strict MIME type > checking is enabled Chrome说“资源解释为样式表,但使用MIME类型text / html传输” - Chrome says “Resource interpreted as Stylesheet but transferred with MIME type text/html” Chrome 71将拒绝执行脚本,因为其MIME类型(&#39;text / x-js&#39;)无法执行 - Chrome 71 will refuse to execute script because its MIME type ('text/x-js') is not executable 拒绝从 &#39;URL&#39; 执行脚本,因为它的 MIME 类型 (&#39;text/html&#39;) 不可执行,并且启用了严格的 MIME 类型检查 - Refused to execute script from 'URL' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled 拒绝从“ file_name.php”执行脚本,因为其MIME类型(“ text / html”)不可执行,并且启用了严格的MIME类型检查 - Refused to execute script from 'file_name.php' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled MIME 类型 (&#39;text/html&#39;) 错误 - MIME type ('text/html') Error Webpack dev服务器抛出错误 - 拒绝执行脚本,因为它的MIME类型('text / html')不可执行 - Webpack dev server throws error - Refused to execute script because its MIME type ('text/html') is not executable
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM