2

I am building a server in Flask that sends my index.html file just fine, but when it requests index.js (which is a module for other js files), the python terminal says it sends index.js, but it doesn't show up on the browser sources.

Server/Browser info:

Browser requests index.html
Server receives request for index.html
Server sends index.html
Browser receives index.html
Browser requests index.js
Server receives request for index.js
Server sends index.js
Browser fails to receive index.js

However, I have another script for other things that is not a module called functions.js, (Evidently modules cannot have content accessible by the console and various other places) it loads, same with style.css.

HTML Link:

<script type="module" src="../static/js/index.js"></script>
<script type="text/javascript" src="../static/js/functions.js"></script>

This is what the console throws

What's frustrating is this issue doesn't happen on a server I made on Node.js, but I want to run the server on Flask because of some other reasons I won't disclose. I have previously received the same error on the browser using the Node.js server, but I recognize that was some problem referring to the combination of type="module" or type="text/javascript" and using js as a module/just a script. Using the same index.html and index.js files as I used on the server run by Node.js, it fails to work on Flask.

Edit: Okay, I think I have the answer, but I'm unsure! Evidently, module js files have the file extension .mjs instead of .js. I don't understand why it worked on the Node.js server and not Flask. Perhaps it's because Node.js can decipher between the two and Flask cannot? I would love more information on this and perhaps other ways to think about this problem!

0

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.