why is this happening to my JavaScript code?

Viewed 27

so this is my code:

<!DOCTYPE html>
<html>
    <head>
        <link rel="stylesheet" href="style.css">
    </head>
    <body>
        <script type="module">
            import * as THREE from 'https://unpkg.com/three@0.126.1/build/three.module.js'
            const scene = new THREE.Scene
            console.log(scene)
        </script>
    </body>
</html>

it works just fine but as soon as i put the "src="script.js" to the script tag, the code suddenly stops working... can somebody explain to me why this is happening?

1 Answers

Each script tag only loads from either src or from within the body, not both. You'll need 2 script tags to load the inline code as well as the script file in one of them each.

Related