Getting error while using GLTFLoader

I am getting error while using GLTFLoader in my vue.js app.

Uncaught TypeError: three_build_three_module_js__WEBPACK_IMPORTED_MODULE_4__.GLTFLoader is not a constructor

Steps to reproduce:

  1. npm install three@0.130.1
  2. import * as THREE from “three/build/three.module.js”
  3. use new THREE.GLTFLoader();

you’ll get error while using GLTFLoader method.

I want help on this. is there any other way t load gltf file…? please let me know.

Thanks in advance.

GLTFLoader is a separate module and no part of three.module.js. Try to import it like so:

import * as THREE from 'three';
import { GLTFLoader} from 'three/examples/jsm/loaders/GLTFLoader.js';

And then create the loader instance like so:

const loader = new GLTFLoader();

Here you can find simple examples :slightly_smiling_face:

From the Collection of examples from discourse.threejs.org

BeginnerExample
// … step 03: load 3D models - gltf

It’s worked. Thanks😊