{"record":{"id":"f333ed3138ce5c14","repo":"BabylonJS/Babylon.js","slug":"draco-encoder-module-is-not-available-f333ed","errorCode":null,"errorMessage":"Draco: Encoder module is not available","messagePattern":"Draco: Encoder module is not available","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/dev/core/src/Meshes/Compression/dracoEncoder.ts","lineNumber":260,"sourceCode":"                    const transferList = [];\r\n                    for (const attribute of attributes) {\r\n                        transferList.push(attribute.data.buffer);\r\n                    }\r\n                    if (indices) {\r\n                        transferList.push(indices.buffer);\r\n                    }\r\n\r\n                    worker.postMessage({ id: \"encodeMesh\", attributes: attributes, indices: indices, options: mergedOptions }, transferList);\r\n                });\r\n            });\r\n        }\r\n\r\n        if (this._modulePromise) {\r\n            const encoder = await this._modulePromise;\r\n            return EncodeMesh(encoder.module, attributes, indices, mergedOptions);\r\n        }\r\n\r\n        throw new Error(\"Draco: Encoder module is not available\");\r\n    }\r\n\r\n    /**\r\n     * Encodes a mesh or geometry into a Draco-encoded mesh data.\r\n     * @param input the mesh or geometry to encode\r\n     * @param options options for the encoding\r\n     * @returns a promise that resolves to the newly-encoded data\r\n     */\r\n    public async encodeMeshAsync(input: Mesh | Geometry, options?: IDracoEncoderOptions): Promise<IDracoEncodedMeshData> {\r\n        const verticesCount = input.getTotalVertices();\r\n        if (verticesCount == 0) {\r\n            throw new Error(\"Draco: Cannot encode geometry with no vertices.\");\r\n        }\r\n\r\n        // Prepare parameters for encoding\r\n        if (input instanceof Mesh && input.morphTargetManager && options?.method === \"MESH_EDGEBREAKER_ENCODING\") {\r\n            Logger.Warn(\"Draco: Cannot use EDGEBREAKER encoding method with morph targets. Falling back to SEQUENTIAL method.\");\r\n            options.method = \"MESH_SEQUENTIAL_ENCODING\";\r","sourceCodeStart":242,"sourceCodeEnd":278,"githubUrl":"https://github.com/BabylonJS/Babylon.js/blob/0592b347b8a4ee0236089ea86a749cacfdb266d8/packages/dev/core/src/Meshes/Compression/dracoEncoder.ts#L242-L278","documentation":"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.","triggerScenarios":"Calling `DracoEncoder.encodeMeshAsync` on a DracoEncoder instance without having called its constructor config/`_instantiateEncoderAsync` path that sets `_modulePromise`, or after module load failed.","commonSituations":"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.","solutions":["Ensure DracoCompression.Configuration includes `encoder: { url: \"<path>/draco_encoder.js\" }` before instantiating/using DracoEncoder.","Verify the encoder module URL loads (network tab, CORS, CSP allows wasm-unsafe-eval).","Create a fresh DracoEncoder instance after a failed load; don't reuse one whose _modulePromise never resolved.","Check `DracoCompression.Configuration.encoder?.available` before encoding and load on demand."],"exampleFix":"// before\nconst encoder = new DracoEncoder();\nconst encoded = await encoder.encodeMeshAsync(mesh);\n\n// after\nDracoCompression.Configuration.encoder = { url: \"https://cdn.babylonjs.com/draco/draco_encoder.js\" };\nconst encoder = new DracoEncoder(); // picks up configured module promise\nconst encoded = await encoder.encodeMeshAsync(mesh);","handlingStrategy":"validation","validationCode":"if (!DracoCompression.Configuration.encoder?.available) {\n    throw new Error(\"Load Draco encoder module before encoding\");\n}\nconst encoded = await encoder.encodeMeshAsync(mesh);","typeGuard":"function encoderReady(): boolean {\n    return !!DracoCompression.Configuration.encoder?.available;\n}","tryCatchPattern":"try {\n    return await encoder.encodeMeshAsync(mesh);\n} catch (e) {\n    if (e instanceof Error && e.message.includes(\"Encoder module is not available\")) {\n        await loadDracoEncoder();\n        return await new DracoEncoder().encodeMeshAsync(mesh);\n    }\n    throw e;\n}","preventionTips":["Configure `DracoCompression.Configuration.encoder.url` before creating a DracoEncoder","Preload the encoder module at startup in encode-heavy pipelines","Don't reuse encoder instances whose initialization failed; create a new one after config is fixed","Verify wasm-unsafe-eval/CSP and CORS for the encoder script and wasm"],"tags":["draco","encoder","initialization","wasm"],"backgroundTag":"module-not-initialized","analyzedSha":"0592b347b8a4ee0236089ea86a749cacfdb266d8","analyzedAt":"2026-08-30T15:11:20.442Z","schemaVersion":2},"datasetVersion":"2026-08-30T18:17:15.746Z"}