In my application I have my javascript in files. I am trying to convert those files to javascript modules.
I need to have some code in my html (in order to generate Django urls - (see this question How to configure a django url correctly in javascript).
html
<html>
<head>
</head>
<body>
<p id="display_text">aaa</p>
</body>
<script type="">
function setText(text) {
var display_text = document.getElementById('display_text');
display_text.innerText = text;
}
</script>
<script type="" src="module.js"></script>
</html>
module.js
setText('module')
This does not seem to work with modules
If I convert the html as follows
<script type="module">
export function setText(text) {
var display_text = document.getElementById('display_text');
display_text.innerText = text
}
</script>
<script type="module" src="module.js"></script>
I get the error
module.js:1 Uncaught ReferenceError: setText is not defined
If I need to import the setText function into module.js, how do I do it?
What am I doing wrong?