[英]using .mjs file extension js modules
I have a problem concerning.js and.mjs file extensions.我有一个关于 .js 和 .mjs 文件扩展名的问题。 When I use
<script type = "module" src="test.js"></script>
as a html script import statement everything works fine.当我使用
<script type = "module" src="test.js"></script>
作为 html 脚本导入语句时,一切正常。
But if I use <script type = "module" src="test.mjs"></script>
as import statement, I get the following error message:但是,如果我使用
<script type = "module" src="test.mjs"></script>
作为导入语句,我会收到以下错误消息:
"Failed to load module script: The server responded with a non-JavaScript MIME type of "". Strict MIME type checking is enforced for module scripts per HTML spec." “加载模块脚本失败:服务器以“”的非 JavaScript MIME 类型响应。按照 HTML 规范对模块脚本强制执行严格的 MIME 类型检查。
I use a local XAMPP Apache Webserver for testing purposes.我使用本地 XAMPP Apache 网络服务器进行测试。 Does somebody know, how I can tell my browser that.mjs is a javascript file?
有人知道,我怎么能告诉我的浏览器 that.mjs 是 javascript 文件?
Thank you for your help!谢谢您的帮助!
If the server does not respond with the correct MIME-Type for .mjs
or other files, you may be able to add this Type in your .htaccess
with如果服务器没有响应
.mjs
或其他文件的正确 MIME 类型,您可以在.htaccess
中添加此类型
<IfModule mod_mime.c>
AddType text/javascript mjs
</IfModule>
That solved the problem for me.这为我解决了问题。
But I also decided to use the .js
extension again for my modules, because I think the time for .mjs
as extension has not come yet.但我也决定再次为我的模块使用
.js
扩展名,因为我认为.mjs
作为扩展名的时间还没有到来。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.