Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

185
Views
Functions other than imported doesn't work inside type='module' script

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.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!