Why the functions declared in type module script don't work and only imported functions do?
I have an HTML file in which there's a script tag:
<script type='module' src="javascripts/script.js"></script>
In scripts.js file I am importing a function from a different file:
import {bfs} from "./algorithms.js"
If i try to use that function in script.js file, everything works. However inside this script.js file, I have different, not imported functions, like so:
function mouseMoved() {
console.log('mouse moved') };
When I run the express server, i get the error:
Uncaught ReferenceError: mouseMoved is not defined at HTMLTableCellElement.onmousemove
But when I delete "type='module'" property from the script tag inside HTML, like so:
<script src="javascripts/script.js"></script>
Then function declared inside this script, like mouseMoved() works perfectly. However the script tag needs to have type='module' attribute in order to make imports work.
I've searched and watched couple of videos explaining modules, but I did not find answer to my problem. I really would love to know how to handle modules in relation to main script tag in HTML file, so that I can important functions inside main script, but also use functions declared in that script.