Reputation: 266
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>
Upvotes: 2
Views: 1002
Reputation: 31076
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();
Upvotes: 3