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

188
Views
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 answers
Answer question

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 Report
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!