Nodejs threejs GLTFExporter (server side) Blob issue




First to thanks in advance to who will waste his time under this question.

: )

I am trying to make a DAE2GLB convertor with very specific optimizations.
# node myConvertor.js input.dae output.glb

I am currently able to open a dae file or gltf/glb file and modify using three modules.

But my problem comes when I try yo use the GLTFExporter in the same way I used ColladataLoader or GLTFLoader because it depends on Blob objects.

UI have look into the other available exporters and ColladaExporter doesn’t use Blobs for anything, the same for STLExporter or ObjectExporter.

Unfortunately as far as I know Blobs are only available under browser context. I tried to search for a valid solution for nodejs on server side and Blob support but I didn’tBest regardsI really need to concluded anything.

I am able to open a DAE,GLTF orI really need to GLB file and modify reIits content (as for example custom buffergeometry vertex attributes) andsave everything into a JSON file.

I would prefer to use GLTF binary format (GLB) because it’s faster.

I am also aware that thre are browser emulation contexts for nodejs as Electron, but I would prefer not using it.

The question is if it would be possible to make GLTFExporter.js usable in a nodejs server runtime context

Best regards


I’ve used the following hack to run GLTFExporter in Node.js —

const THREE = require('three');
const Canvas = require('canvas');
const { Blob, FileReader } = require('vblob');

// Patch global scope to imitate browser environment.
global.window = global;
global.Blob = Blob;
global.FileReader = FileReader;
global.THREE = THREE;
global.document = {
  createElement: (nodeName) => {
    if (nodeName !== 'canvas') throw new Error(`Cannot create node ${nodeName}`);
    const canvas = new Canvas(256, 256);
    // This isn't working — currently need to avoid toBlob(), so export to embedded .gltf not .glb.
    // canvas.toBlob = function () {
    //   return new Blob([this.toBuffer()]);
    // };
    return canvas;


At the time I didn’t find a fix for canvas.toBlob(), so you cannot go directly to .glb, but export to .gltf should work. There are various tools (e.g. for packing glTF to GLB if needed.



Many many thanks for the information.

Could you please attach a full example?

I would prefer to obtain a glb instead a gltf but it is ok.

Best regards


I can’t write a complete DAE Converter for you, but here’s a (more) complete example of the code above:

For a more general purpose converter, you may want to try and then apply the specific optimizations afterward.



First of all thanks a lot for the information.

I tried to install canvas on nodejs, but it has dependencies with external programs I cannot install at work (I am not admin in my PC). I am using a portable nodejs+npm installation.

Anyway using electron I could make GLTFExporter working without any problem in some minutes.

The problem of Electron is that runs in an emulated webbrowser context and this is exactly what I am trying to avoid. I want to make make my convertor (not only a convertor) to run in a headless mode.

Anyway many thanks for you time.


Finally I did it.

Now I can import all supported THREE Formats, apply my own object modifications and finally at the end export one or many models to one or multiple GLB files.

It’s super fast.

: )

Many thanks again for the clue.