Problem with importing several scripts - errors


I’m totally new to three.js and I’m running into some problems while importing scripts.

I’m trying to import a 3D model, which I use the ObjectLoader for. However, when I try to run the model on a localhost, I get an error. I just have my basic index.html file. In there I call the ObjectLoader and the three.js file.

The error I constantly get says:
Uncaught SyntaxError: Unexpected token {

Referring to the ObjectLoader.js file, which starts with:
import {


… and so on.

I tried different loader and all, but it just doesn’t seem to work with me.

The only loader that did work for me was the OBJLoader (which I got from a different folder), but with that loader I can’t seem to load .jpg files for the material.

Please help me, near desperately!


ObjectLoader (and anything else under src/*) is included in three.js automatically, you don’t need load its script and may have issues if you try to do so. Just use THREE.ObjectLoader as-is. :slight_smile:

For files in examples/js, like OBJLoader, you can and should import the scripts separately.

@donmccurdy thank you for the tip.

However, when I do so (not calling the script) I still get an error saying:

three.js:38049 THREE:ObjectLoader: Can’t parse “model.obj”. Unexpected token # in JSON at position 0

Do you know how to fix this error?

P.s. I used this loader:

If you want to load OBJ files, use OBJLoader. ObjectLoader is intended for JSON files in the Object/Scene format.

This error can happen if you load a deprecated JSON format with ObjectLoader. You might want to use JSONLoader in order to avoid this error.

Thank you very much, it worked!