Sherin Shaju
Sherin Shaju

Reputation: 266

Attempted import error: 'OBJLoader' is not exported from 'three' (imported as 'THREE')

while i try to run OBJLoader it give the error. Attempted import error: 'OBJLoader' is not exported from 'three' (imported as 'THREE').

     import * as THREE from "three";
     import OBJLoader from "three-obj-loader";
     OBJLoader(THREE);

         const scene = new THREE.Scene();
            const camera = new THREE.PerspectiveCamera(
              75,
              window.innerWidth / window.innerHeight,
              0.1,
              1000
            );
        
            const renderer = new THREE.WebGLRenderer({ antialias: true });
            renderer.setSize(window.innerWidth, window.innerHeight);
            this.mount.appendChild(renderer.domElement);
        
           const loader = new OBJLoader();

            loader.load(
              "model/Room.obj",
              function (object) {
                scene.add(object);
              },
              function (xhr) {
                console.log((xhr.loaded / xhr.total) * 100 + "% loaded");
              },
              function (error) {
                console.log("An error happened");
              }
            );

Upvotes: 1

Views: 2262

Answers (2)

Leo Seyers
Leo Seyers

Reputation: 340

I ended up copy/pasting the whole module of 'three/examples/jsm/loaders/OBJLoader.js'; (check in the source repo or node module folder) in my current project structure

Then import as you'd usually do

import { OBJLoader } from './OBJLoader'

Upvotes: 0

Mugen87
Mugen87

Reputation: 31076

Please import OBJLoader like so:

import { OBJLoader } from 'three/examples/jsm/loaders/OBJLoader.js';

The usage of three-obj-loader is not required. All example files are available as modules in the three npm package.

Upvotes: 2

Related Questions