为什么我的 javascript 代码没有执行并说不是有效的 mime 类型?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/55649683/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Why my javascript code is not executing and says not a valid mime type?
提问by DEBASHIS BAIDYA
Here I have included the javascripts but I got mime type is not valid :
在这里,我已经包含了 javascripts,但我的 mime 类型无效:
<script type="text/javascript" src="{{ asset('/dashboard/js/components.js') }}"></script>
<script type="text/javascript" src="{{ asset('/dashboard/js/custom.js') }}"></script>
<script type="text/javascript" src="{{ asset('/dashboard/vendors/slimscroll/js/jquery.slimscroll.min.js') }}"></script>
<script type="text/javascript" src="{{ asset('/dashboard/vendors/raphael/js/raphael-min.js') }}"></script>
<script type="text/javascript" src="{{ asset('/dashboard/vendors/d3/js/d3.min.js') }}"></script>
<script type="text/javascript" src="{{ asset('/dashboard/vendors/c3/js/c3.min.js') }}"></script>
And I am getting the error below :
我收到以下错误:
The script from “http://localhost/Project/public/dashboard/vendors/flotchart/js/jquery.flot.pie.js” was loaded even though its MIME type (“text/html”) is not a valid JavaScript MIME type.[Learn More] home
Loading failed for the <script> with source “http://localhost/Project/public/dashboard/vendors/flotchart/js/jquery.flot.pie.js”. home:2091:1
The script from “http://localhost/Project/public/dashboard/vendors/flot.tooltip/js/jquery.flot.tooltip.min.js” was loaded even though its MIME type (“text/html”) is not a valid JavaScript MIME type.[Learn More]
What is the problem ? Please help.
问题是什么 ?请帮忙。
回答by Tuba ádám
What worked for me: After a half day research i tried just to edit the JS file. Just put a new line (ENTER) after the first (commented) line and saved it.
什么对我有用:经过半天的研究,我试图编辑 JS 文件。只需在第一行(注释)之后添加一个新行 (ENTER) 并保存它。
It was jquery minified file with a comment on the beginning. In Firefox "Inspector / Network" the .js was displayed as 404 and MIME (text/html). The strange thing was that the other .js files in the same directory were OK. Hope that helps.
它是 jquery 缩小文件,开头带有注释。在 Firefox "Inspector / Network" 中,.js 显示为 404 和 MIME (text/html)。奇怪的是,同目录下的其他.js 文件都没问题。希望有帮助。
回答by Vishwanath Sharma
I faced the same problem for Node js application. Your scripts path starting with
我在 Node js 应用程序中遇到了同样的问题。您的脚本路径以
/dashboard/js/components.js
so basically you have to use
所以基本上你必须使用
const app = express()
const publicDirectoryPath = path.join(__dirname, '../public/')
app.use(express.static(publicDirectoryPath))

