0

I have a simple html page, which references a javascript module:

<head>
    <script type="module" src="mymodule.js"></script>
</head>

<body onload="doStuff()">
    . . . 

The javascript file looks like this:

export function doStuff() {
    console.log('test');

However, when I run this, I get the error:

columns.html:8 Uncaught TypeError: doStuff is not a function
    at onload (myPage.html:8)

If I change the HTML to:

<script src="mymodule.js"></script>

Then it works; however, this then doesn't let me reference a second javascript library from mymodule.js. My question is, why can it not find the function when it's referenced as a module?

1 Answers1

0
<script>
  import { doStuff } from 'mymodule.js';
</script>
<body onload="doStuff()">
....
</body>
Fakt309
  • 821
  • 5
  • 14