I'm going over three.js, and found this example.
https://threejsfundamentals.org/threejs/lessons/threejs-load-gltf.html
Unfortunately, I keep getting this error for all three imports when I run it locally using Flask.
import * as THREE from 'https://threejsfundamentals.org/threejs/resources/threejs/r122/build/three.module.js';
import {OrbitControls} from 'https://threejsfundamentals.org/threejs/resources/threejs/r122/examples/jsm/controls/OrbitControls.js';
import {GLTFLoader} from 'https://threejsfundamentals.org/threejs/resources/threejs/r122/examples/jsm/loaders/GLTFLoader.js';
Uncaught SyntaxError: Cannot use import statement outside a module
I've looked high and low for solutions, and can't find any.
I've also tried to run the three imports with script tags.
<script src="{{url_for('static',filename='js/three/build/three.js')}}"></script>
<script type="module" src="{{url_for('static',filename='js/three/examples/jsm/controls/OrbitControls.js')}}"></script>
<script type="module" src="{{url_for('static',filename='js/three/examples/jsm/loaders/GLTFLoader.js')}}"></script>
This works, but when I try the code below, I get:
Uncaught ReferenceError: OrbitControls is not defined
const controls = new OrbitControls(camera, canvas);
controls.target.set(0, 5, 0);
controls.update();
Also, if I try either for GLTFLoader, I get an error.
const loader = new THREE.GLTFLoader();
or
const loader = new GLTFLoader();
Any idea how I can solve this would be appreciated.
question from:
https://stackoverflow.com/questions/65864573/cant-import-orbitcontrols-js-with-three-js 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…