javascript - using .mjs file extension js modules - Stack Overflow

I have a problem concerning .js and .mjs file extensions.When I use <script type = "module&quo

I have a problem concerning .js and .mjs file extensions. When I use <script type = "module" src="test.js"></script> as a html script import statement everything works fine.

But if I use <script type = "module" src="test.mjs"></script> as import statement, I get the following error message:

"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."

I use a local XAMPP Apache Webserver for testing purposes. Does somebody know, how I can tell my browser that .mjs is a javascript file?

Thank you for your help!

I have a problem concerning .js and .mjs file extensions. When I use <script type = "module" src="test.js"></script> as a html script import statement everything works fine.

But if I use <script type = "module" src="test.mjs"></script> as import statement, I get the following error message:

"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."

I use a local XAMPP Apache Webserver for testing purposes. Does somebody know, how I can tell my browser that .mjs is a javascript file?

Thank you for your help!

Share Improve this question asked May 14, 2020 at 12:21 MetalheadMetalhead 912 silver badges7 bronze badges 4
  • You've to configure the mime_module in httpd.conf file: AddType application/javascript .mjs. – Teemu Commented May 14, 2020 at 12:30
  • Can I do it somewhere in the html as well? – Metalhead Commented May 14, 2020 at 12:45
  • No, you can't, you need to update the server configuration. – Teemu Commented May 14, 2020 at 12:49
  • It's also possible to get the same error, if the module is not found (i.e. you've an incorrect path/filename), when the server responses with an error page (which is usually html). I'm not aware how to fix this. – Teemu Commented May 14, 2020 at 12:55
Add a ment  | 

1 Answer 1

Reset to default 4

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

<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 e yet.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745360132a4624320.html

相关推荐

  • javascript - using .mjs file extension js modules - Stack Overflow

    I have a problem concerning .js and .mjs file extensions.When I use <script type = "module&quo

    4小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信