I include an external javascript file in my Html file, this javascript file is written by me also. The Html file name is test.html, the javascript file name is test.js. I upload the two files to a local web browser ( if not upload the file test.html, test.js to a web server, you will encounter an error, you can see the reference section at the end of this article to learn more ). And when I access the test.html with the URL http://localhost:8000/test.html, it shows the error message Failed to load module script: Expected a JavaScript module script but the server responded with a MIME type of “text/plain”. This article will tell you how to fix it.
1. How To Fix Failed To Load Module Script: Expected A Javascript Module Script But The Server Responded With A Mime Type Of “text/plain”.
- Below is the detailed error message.
test.js:1 Failed to load module script: Expected a JavaScript module script but the server responded with a MIME type of "text/plain". Strict MIME type checking is enforced for module scripts per HTML spec.
- Below is the test.html file source content code.
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Example<title> <script type="module" src="test.js" ></script> </head> <body> ...... </body> </html>
- The reason is that the type attribute’s value ( “module” ) of the source code <script type=”module”></script>.
- You should change the type attribute’s value to “text/javascript” like below.
<script type="text/javascript" src="test.js" ></script>
- Now when you browse the test.html file in a web browser again, the error will disappear.
References
I have been attempting to find a solution since last night thank you man i did not know how to change the type XD