服务器以“图像/png”的MIME类型响应。 -html / javaScript
我正在使用HTML和JavaScript构建类似Mario的游戏,现在几乎完成了,我想通过图像更改矩形(平台)。
这是我的结构:
- index.html
- index.js
- index.css
- /assets/platform.png
在我的index.js
中导入我的图像: 从'./assets/platform.png'
浏览器返回此错误:
无法加载模块脚本:预期一个JavaScript模块脚本,但服务器以“ Image/png”的MIME类型响应。严格的MIME类型检查是针对每个HTML规格的模块脚本执行的。
我正在使用VSCODE的实时服务器。
有什么帮助吗?
I'm building a mario-like game with HTML and JavaScript, and now that it is almost done, i'd like to change my rectangles (the platforms) by images.
Here is my structure :
- index.html
- index.js
- index.css
- /assets/platform.png
To import my image, in my index.js
I did :import platform from './assets/platform.png'
Browser return this error :
Failed to load module script: Expected a JavaScript module script but the server responded with a MIME type of "image/png". Strict MIME type checking is enforced for module scripts per HTML spec.
I am using Live Server from VSCode.
Any help on this ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您可以使用添加
img
src
用JS动态属性:You can use add
img
src
attribute dynamically with js:导入用于导入脚本。您导入图像。
Import is for importing scripts. You import image.
伙计,这并不容易解决,但是我认为您正在尝试用“导入图像”来引用图像,
而不是这样,您将图像引用在const。中,并且图像源必须是URL从您在github上的存储库。
const image =新图像()
image.src ='http://127.0.0.1:5500/src/imagens/platform_c.png'
Man, that's not that easy to solve, but i think that you are trying to reference the image with "import image from"
Don't do that, you shoul reference the image in a const., and the image source must be a url from your repository on github.
const image = new Image()
image.src = 'http://127.0.0.1:5500/src/imagens/Platform_C.png'
这将肯定可行100000%。只需在JS文件的顶部添加此代码行
this will work im 100000% sure. Just add this line of code on top of your JS file