Importing OribitControls doesn't work with error in three.js

Viewed 29

I'm working in localhost, I tried to import "orbitcontrols()" but somehow it doesn't work and show error. The error is here

main.js:1 Uncaught SyntaxError: Cannot use import statement outside a module (at main.js:1:1)

and this is how i imported the orbitcontrols() in my main.js

import {OrbitControls} from "./examples/jsm/controls/OrbitControls";

//...there are scene, camera and renderer etc

const controls = new OrbitControls(camera,canvas)
controls.enableDamping = true 

function animate() {

    requestAnimationFrame( animate );

    controls.update();

    renderer.setSize(sizes.width, sizes.height);
    renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2))
    renderer.render(scene,camera);

}
animate()

and this is my index.html

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>만들어보아요.01</title>
        <link rel="stylesheet" href="style.css">
    </head>
    <body>
        <canvas class="webgl"></canvas>
        <script src="./three.min.js"></script>
        <script src="main.js"></script>
    </body>
</html>

and this is my folder

folders

someFolder
 | 
 ├ -index.html
 ├ -main.js
 ├ -three.min.js
 ├ -style.css
 ├ -package-lock.json
 |
 ├ -build
 | |
 | +-three.module.js
 |
 +-examples
   |
   +-jsm
     |
     +-controls
       |
       +-OrbitControls.js
      

     ...

may be i used 'three.min.js' file instead 'three.js'?

I would be appreciate so much, if anyone give advice me .

1 Answers
Related