{"id":27552,"library":"wgsl-wasm-transpiler-bundler","title":"wgsl-wasm-transpiler-bundler","description":"A Rust-based WGSL shader compiler and cross-transpiler that converts WGSL to GLSL, HLSL, Metal, or SPIR-V. v0.0.1 is an early release with no regular release cadence yet. Differentiators: runs in Node.js and browser via WASM, single-function API, supports SPIR-V binary and assembly output. Requires manual WASM initialization via `init()` before any compilation calls. Competing with naga and glslang, but lighter and purely WGSL→others.","status":"active","version":"0.0.1","language":"javascript","source_language":"en","source_url":"https://github.com/reczkok/wgsl-wasm-transpiler","tags":["javascript","typescript"],"install":[{"cmd":"npm install wgsl-wasm-transpiler-bundler","lang":"bash","label":"npm"},{"cmd":"yarn add wgsl-wasm-transpiler-bundler","lang":"bash","label":"yarn"},{"cmd":"pnpm add wgsl-wasm-transpiler-bundler","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"ESM; named export only. No default export.","wrong":"import compileShader from 'wgsl-wasm-transpiler-bundler'","symbol":"compileShader","correct":"import { compileShader } from 'wgsl-wasm-transpiler-bundler'"},{"note":"Required before compileShader. Returns a promise in browser (await), sync in Node (call once).","wrong":"const init = require('wgsl-wasm-transpiler-bundler')","symbol":"init","correct":"import { init } from 'wgsl-wasm-transpiler-bundler'"},{"note":"Returns string array like ['wgsl','glsl','hlsl','metal','spirv','spirv-asm'].","symbol":"getSupportedFormats","correct":"import { getSupportedFormats } from 'wgsl-wasm-transpiler-bundler'"}],"quickstart":{"code":"import { init, compileShader } from 'wgsl-wasm-transpiler-bundler';\n\nconst wgsl = `@fragment fn main() -> @location(0) vec4<f32> {\n  return vec4<f32>(1.0, 0.0, 0.0, 1.0);\n}`;\n\n// Browser: await init(); Node: init(); then use\nawait init();\nconst glsl = compileShader(wgsl, 'glsl');\nconsole.log(glsl);","lang":"typescript","description":"Initialize WASM and compile a trivial WGSL fragment shader to GLSL."},"warnings":[{"fix":"Always call init() (and await in browser) before any other API function.","message":"Calling compileShader before init() throws: 'WASM not initialized' or panics.","severity":"breaking","affected_versions":">=0.0.1"},{"fix":"Use await init() in both environments; it works in Node too.","message":"init() is synchronous in Node.js but asynchronous in browser. If you await in Node, it's fine, but forgetting await in browser will cause a runtime error.","severity":"gotcha","affected_versions":">=0.0.1"},{"fix":"Validate WGSL before passing. Use getSupportedFormats() to check format. Wrap in try/catch.","message":"compileShader throws on invalid WGSL or unsupported format. Unclear error messages may mention Rust panics.","severity":"gotcha","affected_versions":">=0.0.1"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Use import { compileShader } from 'wgsl-wasm-transpiler-bundler'","cause":"Importing default instead of named export.","error":"TypeError: compileShader is not a function"},{"fix":"Ensure you are using the correct path to the WASM file and call init() with await.","cause":"WASM binary not loaded or init() not called properly.","error":"RuntimeError: unreachable (or WebAssembly.instantiate(): expected magic word)"},{"fix":"Use 'spirv' for binary or 'spirv-asm' for text. Run getSupportedFormats() to see all.","cause":"Using wrong format string; must be exactly one of the supported formats.","error":"Error: Unknown format: 'spirv_binary'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}