{"record":{"id":"07c2861a390d057d","repo":"BabylonJS/Babylon.js","slug":"twgsl-is-not-available","errorCode":null,"errorMessage":"twgsl is not available.","messagePattern":"twgsl is not available\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/dev/core/src/Engines/WebGPU/webgpuTintWASM.ts","lineNumber":64,"sourceCode":"            ...twgslOptions,\r\n        };\r\n\r\n        if (twgslOptions.twgsl) {\r\n            WebGPUTintWASM._Twgsl = twgslOptions.twgsl;\r\n            return;\r\n        }\r\n\r\n        if (twgslOptions.jsPath && twgslOptions.wasmPath) {\r\n            await Tools.LoadBabylonScriptAsync(twgslOptions.jsPath);\r\n        }\r\n\r\n        if ((self as any).twgsl) {\r\n            // eslint-disable-next-line require-atomic-updates\r\n            WebGPUTintWASM._Twgsl = await (self as any).twgsl(Tools.GetBabylonScriptURL(twgslOptions.wasmPath!));\r\n            return;\r\n        }\r\n\r\n        throw new Error(\"twgsl is not available.\");\r\n    }\r\n\r\n    public convertSpirV2WGSL(code: Uint32Array, disableUniformityAnalysis = false): string {\r\n        const ccode = WebGPUTintWASM._Twgsl.convertSpirV2WGSL(code, WebGPUTintWASM.DisableUniformityAnalysis || disableUniformityAnalysis);\r\n        if (WebGPUTintWASM.ShowWGSLShaderCode) {\r\n            Logger.Log(ccode);\r\n            Logger.Log(\"***********************************************\");\r\n        }\r\n        return WebGPUTintWASM.DisableUniformityAnalysis || disableUniformityAnalysis ? \"diagnostic(off, derivative_uniformity);\\n\" + ccode : ccode;\r\n    }\r\n}\r\n","sourceCodeStart":46,"sourceCodeEnd":76,"githubUrl":"https://github.com/BabylonJS/Babylon.js/blob/0592b347b8a4ee0236089ea86a749cacfdb266d8/packages/dev/core/src/Engines/WebGPU/webgpuTintWASM.ts#L46-L76","documentation":"WebGPUTintWASM relies on the external twgsl library (loaded from twgsl.js, which wraps the Tint WASM SPIR-V to WGSL translator) to convert SPIR-V shaders. initTwgsl throws when (self).twgsl is undefined, meaning the twgsl script was not loaded into the page before initialization. Without it, WGSL shaders cannot be produced from SPIR-V in the WebGPU engine.","triggerScenarios":"Calling WebGPUTintWASM.InitTwgsl (or creating a WebGPUEngine that needs shader conversion) when the twgsl script (twgsl.js) was never included / loaded via script tag or dynamic import.","commonSituations":"Bundlers tree-shaking or not copying twgsl.js/wasm assets; missing twgslUrl/twgslJsPath/twgslWasmUrl options in WebGPUEngine creation; CORS or 404 when loading twgsl.js from CDN; offline environments where the WASM fetch fails so the global never registers.","solutions":["Load twgsl.js before init: add <script src=\"https://cdn.babylonjs.com/twgsl/twgsl.js\"></script> or import it dynamically","Pass correct twgslOptions: { twgslJsPath, twgslWasmPath } pointing to valid, same-origin (or CORS-enabled) URLs","Verify the global is present before init: check window.twgsl / self.twgsl exists","Ensure the .wasm file is served with correct MIME type (application/wasm) and is reachable"],"exampleFix":"// before\nawait WebGPUTintWASM.InitTwgsl(); // twgsl.js never loaded -> throws\n// after\nawait WebGPUFrameGraphRunnerScriptLoader... // or simply:\nawait ThinEngine._LoadScriptAsync('https://cdn.babylonjs.com/twgsl/twgsl.js');\nawait WebGPUTintWASM.InitTwgsl({ twgslWasmPath: 'https://cdn.babylonjs.com/twgsl/twgsl.wasm' });","handlingStrategy":"fallback","validationCode":"if (typeof (self as any).twgsl !== 'function') {\n  await ThinEngine._LoadScriptAsync('https://cdn.babylonjs.com/twgsl/twgsl.js');\n}\nawait WebGPUTintWASM.InitTwgsl({ twgslWasmPath: 'https://cdn.babylonjs.com/twgsl/twgsl.wasm' });","typeGuard":"function isTwgslAvailable(w: unknown): w is { twgsl: (url: string) => Promise<unknown> } {\n  return typeof (w as any)?.twgsl === 'function';\n}","tryCatchPattern":"try {\n  await WebGPUTintWASM.InitTwgsl(twgslOptions);\n} catch (e) {\n  if (e instanceof Error && e.message === 'twgsl is not available.') {\n    await ThinEngine._LoadScriptAsync(twgslJsUrl); // lazy-load then retry once\n    await WebGPUTintWASM.InitTwgsl(twgslOptions);\n  } else throw e;\n}","preventionTips":["Include twgsl.js via script tag or bundled import before engine creation","Always pass explicit twgslWasmPath matching your hosting layout","Verify WASM MIME type (application/wasm) on your server","Add a startup check for self.twgsl before creating a WebGPUEngine"],"tags":["webgpu","wasm","spirv","wgsl","missing-dependency"],"backgroundTag":"missing-external-script","analyzedSha":"0592b347b8a4ee0236089ea86a749cacfdb266d8","analyzedAt":"2026-08-30T15:11:20.442Z","schemaVersion":2},"datasetVersion":"2026-08-30T18:17:15.746Z"}