GLTFLoader not working

I’m having trouble getting the GLTFLoader to work. I don’t know if it is the <script> link that is the problem or the code.

I keep getting an error on the following line

let loader = new THREE.GLTFLoader();

TypeError: undefined is not a constructor (evaluating ‘new THREE.GLTFLoader()’)

When I remove the THREE and do it as the documentation says I get a different error:

let loader = new GLTFLoader();

ReferenceError: Can’t find variable: GLTFLoader

Im at a loss for how to fix this and honestly am not even sure if I’m properly loading the module.

Thanks in advance.

You are mixing global scrips with ES6 modules. Try it like so:

The idea is to use ES6 import for your entire three.js related logic.

1 Like

Well I’ll be…I tried adding that link via import, script, and in the settings and couldn’t get it to work.

So what I should do from now on is load the three.min.js as an import and then all other modules as imports also.

Thanks a ton. Some of the simple things have been tripping me up badly.

You should actually load three.module.js. That’s a different build file.

1 Like

@Mugen87 thanks a ton for that tip. I greatly appreciate the help you do around the forums. I see your name everywhere and as a new guy to this I’ll probably need a ton of help along the way to becoming a pro.

1 Like