Failed to load module script: The server responded with a non-JavaScript MIME type of "text/plain". Strict MIME type checking is enforced for module scripts per HTML spec.
I get this error in chrome after trying to add this line to my HTML code:
<script type="module">import * as hello from './__target__/hello.js'; window.hello = hello;</script>
<!-- From the official documentation of Transcrypt -->
I've been trying to fix for hours, someone suggested to change the type to text/javascript and to use the src tag (src = './__ target__/hello.js') but I need some imports in hello.js
FIXED: Ok I was starting the server with 'python -m http.server' from command line, I just replaced it with this python2 script:
#Use to create local host
import SimpleHTTPServer
import SocketServer
PORT = 8000
Handler = SimpleHTTPServer.SimpleHTTPRequestHandler
Handler.extensions_map.update({
".js": "application/javascript",
});
httpd = SocketServer.TCPServer(("", PORT), Handler)
print ("Serving at port", PORT)
print(Handler.extensions_map[".js"])
httpd.serve_forever()
This question (and the script involved) really helped me a lot. I have modified the script provided in the answer to make it compatible with python3.
#Use to create local host
import http.server
import socketserver
PORT = 1337
Handler = http.server.SimpleHTTPRequestHandler
Handler.extensions_map.update({
".js": "application/javascript",
});
httpd = socketserver.TCPServer(("", PORT), Handler)
httpd.serve_forever()
The notable changes are:-
Changed SimpleHTTPServer to http.server. From python3 onwards , SimpleHTTPServer has become a part of http.server
Changed SocketServer module to socketserver
The functions are backward compatible.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With