Jooonnnaass
Jooonnnaass

Reputation: 13

Threejs Scene not working in my project / THREE not defined

I wanted to create m first three js project and followed a tutorial. But when my page loads no scene is showing up. The sscene should be completly black but the site is just white.

Chrome Browser Console:

three.js:1 Failed to load resource: net::ERR_FILE_NOT_FOUND main.js:1 Uncaught SyntaxError: Cannot use import statement outside a module

My vs code workspace;

enter image description here

My html and js code:

function main(){

    var scene = new THREE.Scene();
    var camera = new THREE.PerspectiveCamera(45,window.innerWidth/window.innerHeight,1,1000);
    var renderer = new THREE.WebGLRenderer();

    renderer.setSize(window.innerWidth,window,innerHeight);
    document.getElementById('webgl').appendChild(renderer.domElement);
    renderer.render(scene,camera);
}

main();
<!DOCTYPE html>

<html>
    <head>
        <title>Three js test</title>
        <style type="text/css">html, body {margin: 0; padding: 0; overflow: hidden;}</style>
    </head>
    <body>
        <div id="webgl"></div>
        <script src="/lib/three.js"></script>
        <script src="./main.js"></script>
    </body>
</html>

Upvotes: 0

Views: 975

Answers (2)

Jooonnnaass
Jooonnnaass

Reputation: 13

I ended up working with the live server extension of vs code and used the three.module.js.

It worked using this.

Upvotes: 0

Neil
Neil

Reputation: 8121

<script src="lib/three.js"></script>

Maybe try removing the '/' from your three.js path?

Upvotes: 1

Related Questions