Using THREE OBJLoader in Gatsby Production Build

270 Views Asked by At

I'm trying to add a threejs scene to my gatsby project.

After some spilled blood I got it working properly in development and building also succeeds but when serving the app I get 3 times the following error:

TypeError: (void 0) is not a constructor

I identified with logs that the error appears on using the OBJLoader constructor. How can I get it working?

This is how I basically set it up:

import React from "react";
import * as THREE from "three";
import * as OBJLoader from "three-obj-loader"

OBJLoader(THREE);

const SceneComponent = (}) => {

   const manager = new THREE.LoadingManager();

   manager.onLoad = () => {
     animate()
   };

  const loader = new THREE.OBJLoader(manager).load(`PATH`, (spoon) => {
    scene.add(spoon)
  }
 ...
}

1

There are 1 best solutions below

0
Theodor Golo Hillmann On

If anybody is interested: I solved this issue by switching to 'three-gltf-loader' and converting the mesh to ".glb", this seems to be best practice as it also halfs the file size.