Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why a module is shown connected but still not working?

Whenever I connect a JS module, in DevTools’ "Sources", the module is shown as connected.
However, the function that I try to run out of it, simply doesn’t work.

What can be done to run the function from the module?

function consoleLog () {
    console.log('The module is working')
}

export default consoleLog;
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script type="module" src="./module.js">
        import consoleLog from './module';
        consoleLog();
    </script>
</head>
<body>

</body>
</html>

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Your problem is that you have code and an src attribute on your script tag, script tags should have one or the other. You also don’t have to create a script tag for your module if you import it in another module, like so:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script type="module">
        import consoleLog from './module.js';
        consoleLog();
    </script>
</head>
<body>

</body>
</html>

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading