How to use DRACOLoader with GLTFLoader in ReactJs?

I have a use case in which I am trying to load a GLTF file which is compressed using DRACO-Compression. I am able to run it using plain javascript but I am facing issues integrating the loader with ReactJs.

What I am doing:

The error I am getting - DracoDecoderModule is not defined

In my app, this is how I am importing:

  import DRACOLoader from './DRACOLoader'

DRACOLoader.js file I am using - DRACOLoader.js (19.3 KB)

Hello Shantanu!

Try to add this before the line that’s giving you trouble

/global DracoDecoderModule :true/
/eslint no-undef: “error”/18

No, it doesn’t help me - it compiles fine after adding these two lines but when catching the error it says the same thing:

errored ReferenceError: DracoDecoderModule is not defined
at eval (DRACOLoader.js:502)
at new Promise (<anonymous>)
at eval (DRACOLoader.js:488)

Are you defining your DracoDecoderModule? It looks like it’s being attached to THREE scope. I’d import this file somewhere in your main.js and try to reference it by THREE.DRACOLoader or somethign like that.

In DRACOLoader.js file, I am doing this:

  • var THREE = require(‘three’)
  • export default THREE.DRACOLoader

You can see these changes in the DRACOLoader.js file that I have attached in my question’s description section.

Are you defining your DracoDecoderModule?

I am not touching anything for this module which is in draco_decoder.js file.

You can find the solution here: