Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

187
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda