Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

188
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda