My threejs project wont let me import gltf models

i tryed to import my gltf loader but it say this :
Uncaught SyntaxError: Unexpected token ‘:’ (at g.gltf?import:2:14)
please iam new in THREE.js i need help
my js file is down
App.jsx (6.7 KB)

Maybe your program is treating the GLTF file as a JS module.

1 Like

how do i make it right

Hi. Sorry for my late reply.
In my experience, there are many types of error in non-loading the gltf file. In your case, it seems to browser problem. Actually, I have experienced this same problem when I was fresh three.js.
Please change the browser version or into other browser.
If it remains after doing this, let’s discuss in more detail.
I understand your mind. I was same when I was first in three.js.

1 Like

hi , i tryed 3 different browsers but didnt work
and thx u for reply

Okay, I see.
I have experienced your case. Let’s check your code in more detail.
Normally, gltf loader act well so if this is not browser problem, It seems gltf loader or path of the model. Please check the path of model or use of gltf loader.
In your code,
import model from ‘./assets/g.gltf’
loader.load(model, (gltf) => {
scene.add( gltf.scene );
It is not correct strictly, the position of the model in your code is path of that model.
so it should be fixed like this.
loader.load( ‘./assets/g.gltf’, (gltf) => {
scene.add( gltf.scene );
if this doesn’t act, you should check whether assets folder is inside of public folder.
And if it doesn’t act again, let’s discuss in more detail.

this show up after using ur fix

TypeError: NetworkError when attempting to fetch resource.

Okay. This is clear Path problem.
Please check whether asset folder is in public folder
and if exist there, you should write like this:
loader.load( ‘assets/g.gltf’, (gltf) => {
scene.add( gltf.scene );
I wish it will help you.

it worked fine finally thank you very much

I’m very glad for hearing your work is going well.
Thanks for your passion.
I wish we will help each other in the future.

1 Like

Peoples using Vitejs running into this issue can use this

import dungeon from '../models/scene.gltf?url'