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

187
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
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