BabylonJS/Babylon.js · error · Error

Draco: Encoder module is not available

Error message

Draco: Encoder module is not available

What it means

DracoEncoder._encodeAsync throws when `this._modulePromise` is null, meaning the encoder module (WASM/JS) was never loaded, so there is no DracoEncoderModule to encode with. Unlike the decoder, the encoder must be explicitly initialized with a module URL.

Source

Thrown at packages/dev/core/src/Meshes/Compression/dracoEncoder.ts:260

                    const transferList = [];
                    for (const attribute of attributes) {
                        transferList.push(attribute.data.buffer);
                    }
                    if (indices) {
                        transferList.push(indices.buffer);
                    }

                    worker.postMessage({ id: "encodeMesh", attributes: attributes, indices: indices, options: mergedOptions }, transferList);
                });
            });
        }

        if (this._modulePromise) {
            const encoder = await this._modulePromise;
            return EncodeMesh(encoder.module, attributes, indices, mergedOptions);
        }

        throw new Error("Draco: Encoder module is not available");
    }

    /**
     * Encodes a mesh or geometry into a Draco-encoded mesh data.
     * @param input the mesh or geometry to encode
     * @param options options for the encoding
     * @returns a promise that resolves to the newly-encoded data
     */
    public async encodeMeshAsync(input: Mesh | Geometry, options?: IDracoEncoderOptions): Promise<IDracoEncodedMeshData> {
        const verticesCount = input.getTotalVertices();
        if (verticesCount == 0) {
            throw new Error("Draco: Cannot encode geometry with no vertices.");
        }

        // Prepare parameters for encoding
        if (input instanceof Mesh && input.morphTargetManager && options?.method === "MESH_EDGEBREAKER_ENCODING") {
            Logger.Warn("Draco: Cannot use EDGEBREAKER encoding method with morph targets. Falling back to SEQUENTIAL method.");
            options.method = "MESH_SEQUENTIAL_ENCODING";

View on GitHub (pinned to 0592b347b8)

Solutions

  1. Ensure DracoCompression.Configuration includes `encoder: { url: "<path>/draco_encoder.js" }` before instantiating/using DracoEncoder.
  2. Verify the encoder module URL loads (network tab, CORS, CSP allows wasm-unsafe-eval).
  3. Create a fresh DracoEncoder instance after a failed load; don't reuse one whose _modulePromise never resolved.
  4. Check `DracoCompression.Configuration.encoder?.available` before encoding and load on demand.

Example fix

// before
const encoder = new DracoEncoder();
const encoded = await encoder.encodeMeshAsync(mesh);

// after
DracoCompression.Configuration.encoder = { url: "https://cdn.babylonjs.com/draco/draco_encoder.js" };
const encoder = new DracoEncoder(); // picks up configured module promise
const encoded = await encoder.encodeMeshAsync(mesh);
Defensive patterns

Strategy: validation

Validate before calling

if (!DracoCompression.Configuration.encoder?.available) {
    throw new Error("Load Draco encoder module before encoding");
}
const encoded = await encoder.encodeMeshAsync(mesh);

Type guard

function encoderReady(): boolean {
    return !!DracoCompression.Configuration.encoder?.available;
}

Try / catch

try {
    return await encoder.encodeMeshAsync(mesh);
} catch (e) {
    if (e instanceof Error && e.message.includes("Encoder module is not available")) {
        await loadDracoEncoder();
        return await new DracoEncoder().encodeMeshAsync(mesh);
    }
    throw e;
}

Prevention

When it happens

Trigger: Calling `DracoEncoder.encodeMeshAsync` on a DracoEncoder instance without having called its constructor config/`_instantiateEncoderAsync` path that sets `_modulePromise`, or after module load failed.

Common situations: Using `new DracoEncoder()` without configuring `encoder = { url: ... }` in DracoCompression.Configuration; blocked WASM load (CSP/CORS/offline); reusing an encoder instance whose initialization promise rejected earlier.

Related errors


AI-assisted analysis of BabylonJS/Babylon.js@0592b347b8 (2026-08-30). Data as JSON: /api/errors/f333ed3138ce5c14. Report an issue: GitHub.