捆绑的JS失败-MIME类型('text/html')无法执行,并且启用了严格的MIME类型检查 [英] Bundled JS fails - MIME type ('text/html') is not executable, and strict MIME type checking is enabled
问题描述
我正在尝试为 Angular/Electron 应用设置基本种子.我已经根据一些指南和文章从头开始研究了它,并且在开发过程中效果很好,但是在我构建它时却失败了.
项目源
git clone https://popClingwrap@bitbucket.org/popClingwrap/angular-electron-seed.git
如果您执行 npm start
,然后在另一个终端中同时 npm run electronic
,则该应用程序将在浏览器和电子应用程序中正常启动窗户.如果您单击屏幕上的按钮,它将在您的桌面上创建一个新目录,因此一切似乎都已正确连接.
如果您随后执行 npm run build
,它将把所有内容捆绑在一起,没有任何错误,但是我认为我应该能够提供捆绑包,并再次在浏览器中运行该应用程序.但是,如果我执行 npm run dev
来启动/dist
目录中的服务器,我只会得到一则有关javascript和样式表的错误列表,
拒绝使用[url]中的样式/拒绝执行[url]中的脚本,因为它的MIME类型('text/html')不是受支持的样式表MIME类型,并且启用了严格的MIME检查.
我将承认,我正在努力了解此构建中正在发生的事情的细节,尤其是在涉及WebPack的情况下.谁能告诉我这里出了什么问题以及我可以尝试解决什么问题?
全力以赴
在index.html中,请验证下面的代码是否与此相同(如果缺少,请在index.html中添加):>
< base href ="/">
这解决了我的问题.
I'm trying to set up a basic seed for an Angular / Electron app. I've worked it up from scratch based on a handful of guides and articles and it works fine whilst developing but fails when I go to build it.
Project Source
git clone https://popClingwrap@bitbucket.org/popClingwrap/angular-electron-seed.git
If you do npm start
then npm run electron
at the same time in a second terminal the app will fire up fine in both a browser and then in an Electron app window. If you click the button on screen it will create a new directory on your desktop so everything seems to be hooked up ok.
If you then do npm run build
it will bundle everything up without any errors but I thought I should then be able to serve the bundles and see the app run in browser again. However if I do npm run dev
to start a server in the /dist
directory I just get a list of errors for both javascript and style sheets saying
Refused to apply styles from / Refused to execute script from [url] because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled.
I'll confess I'm struggling to understand the details of a lot of what is going on in this build especially where WebPack is concerned. Can anyone tell me what is going wrong here and what I might try to fix the issue?
Cheers all
In the index.html, Please verify whether the below code is same like this(incase if it is missing please add this in index.html) :
<base href="/">
This has solved my problem.
这篇关于捆绑的JS失败-MIME类型('text/html')无法执行,并且启用了严格的MIME类型检查的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!