I’m working on a project using Vite, Three.js and Bootstrap where I’m trying to load a .glb model. My project structure is as follows:
my-project/
├── public/
│ ├── models/
│ │ └── Flamingo.glb
├── src/
│ ├── js/
│ │ └── main.js
│ └── scss/
│ | └── styles.scss
| └── index.html
├── package-lock.json
├── package.json
└── vite.config.js
I’m loading the model using GLTFLoader
in main.js:
import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader.js';
const loader = new GLTFLoader();
loader.load(
'/models/Flamingo.glb',
gltf => console.log(gltf.scene),
undefined,
error => console.error(error)
);
When I run my server, I get a 200 OK status for the model URL. However, I’m encountering the following error:
TypeError: Cannot read properties of undefined (reading ‘fetchStack’)
at _0x3131c3.Response.. [as arrayBuffer] (eval at (localhost/:1:76), :1:41458)
Here is my vite configuation:
import { resolve } from 'path'
export default {
root: resolve(__dirname, 'src'),
publicDir: '../public',
build: {
outDir: '../dist'
},
server: {
port: 5173
}
}
I’ve tried various solutions including checking the Three.js version, verifying CORS settings, and ensuring asynchronous operations are handled correctly, but the error persists.