app.js:63 Uncaught ReferenceError: GLTFLoader is not defined

Viewed 545

When i call this in three.js const loader = new GLTFLoader(); get this error app.js:63 Uncaught ReferenceError: GLTFLoader is not defined. it is import in index.html.but got that error

<script src="./three.min.js"></script>
<script src="./OBJLoader.js"></script>
<script src="./GLTFLoader.js"></script>
<script src="./app.js"></script>
1 Answers

A code like const loader = new GLTFLoader(); only works if you import GLTFLoader as an ES6 module via import statement. When doing so, GLTFLoader is no part of the THREE namespace.

Since you are using three.min.js, you are not using a module based workflow but global scripts. That means GLTFLoader is only available under the THREE namespace. So changing your code to the following should fix the issue:

const loader = new THREE.GLTFLoader();
Related