OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

function in my javascript module is not defined

  • Thread starter Thread starter Dmitrii2333
  • Start date Start date
D

Dmitrii2333

Guest
I'm writing JavaScript for the browser, my script.js has something like

Code:
import { foo, bar } from "./lib/sth.js"
function main() { ... }

Then I have this in my browser:

Code:
<script type=module src="./script.js"></script>
<body onload="main();"> ... </body>

But it's keep giving me this error:

Uncaught ReferenceError: main is not defined at onload ((index):7)

Why is my main now defined? It works fine before I use type=module, but with the import statement, I believe it has to be type=module

<p>I'm writing JavaScript for the browser, my script.js has something like </p>

<pre><code>import { foo, bar } from "./lib/sth.js"
function main() { ... }
</code></pre>

<p>Then I have this in my browser:</p>

<pre><code><script type=module src="./script.js"></script>
<body onload="main();"> ... </body>
</code></pre>

<p>But it's keep giving me this error:</p>

<blockquote>
<p>Uncaught ReferenceError: main is not defined
at onload ((index):7)</p>
</blockquote>

<p>Why is my main now defined? It works fine before I use type=module, but with the import statement, I believe it has to be type=module</p>
 

Latest posts

Top