从webpack加载bundle.js文件会将mime类型更改为text/html [英] loading a bundle.js file from webpack changes mime type to text/html

查看:89
本文介绍了从webpack加载bundle.js文件会将mime类型更改为text/html的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用react-redux为应用程序实现服务器端渲染,并为服务器表达内容,正在使用webpack创建捆绑包.

I am trying to achieve server side rendering for an app using react-redux and express for the server, webpack is being used to create the bundle.

我开始使用以下文档:

https://redux.js.org/docs/recipes/ServerRendering.html

我有以下设置来加载从webpack创建的main.js:

I have the following set up to load up the main.js created from webpack:

<script type="application/javascript" src="/static/main.js"></script>

虽然在启动Express服务器时,这是我在控制台中看到的:

On firing up the express server though, this is what I see in the console:

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.

这不会在任何浏览器中触发.知道会发生什么吗?

This is not firing up in any browser. Any idea what might be going on?

推荐答案

在我看来,这是配置问题.

It seems to me as configuration issue.

如果返回的是 MIME类型('text/html'),则意味着在该特定路径下,它无法找到/解析 main.js 文件,因此它将返回默认的404 html页面,该页面严格定义为javascript.

If it is returning MIME type ('text/html') that means, at that specific path it is not able to find/resolve the main.js file, so it is returning a default 404 html page instead, which is strictly defined to be javascript.

因此,理想情况下,您可以做的是将快速服务器配置为提供静态文件,如下所示.

So, Ideally what you can do is that you can configure your express server to serve static files as shown below.

app.use(express.static(__dirname + "/static"));

有关更多详细信息,您可以参考::-> https://expressjs.com/en/starter/static-files.html

For more details, you can refer to::-> https://expressjs.com/en/starter/static-files.html

 

快乐编码!

这篇关于从webpack加载bundle.js文件会将mime类型更改为text/html的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆