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

192
Visualizações
How to use JavaScript modules?

I'm looking to do a simple process using the skypack (https://cdn.skypack.dev/) module in javascript.

I have described the following script.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>sample</title>
</head>
<body>
    <button id="button" onclick="mybutton">click</button>
    <!-- <script type="module" src="https://cdn.skypack.dev/@...<modulename>...">// <- Uncaught ReferenceError: mybutton is not defined -->
    <script type="text/javascript" src="https://cdn.skypack.dev/@...<modulename>...">// <- Uncaught SyntaxError: export declarations may only appear at top level of a module
        import { METHOD } from "<modulename>";
        function mybutton(){
            console.log("aaa");
            // ... snip ...
        }
    </script>
</body>
</html>

However, the module does not work in the script tag.

I have tried two things.

  1. import in the script tag.

This gave me the following error.

Uncaught SyntaxError: export declarations may only appear at top level of a module.

It seems that you need to use <script type="module" when importing a module.

  1. do script type="module" .

This gave the following error:

Uncaught ReferenceError: mybutton is not defined.

It seems that the function defined directly below is not found.

What can I do to resolve these?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I will post the code that worked.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<body>
    <button id="button">click</button>
    <script type="module">
        document.getElementById('button').addEventListener('click', mybutton);
        import { METHOD } from "https://cdn.skypack.dev/.../<modulename>";
        function mybutton(){
            console.log("aaa");
            // METHOD(arg); ...
            // ... snip ...
        }
    </script>
</body>
</html>
about 4 years ago · Juan Pablo Isaza Relatório
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