Skip to content

Latest commit

 

History

History
23 lines (20 loc) · 1.21 KB

File metadata and controls

23 lines (20 loc) · 1.21 KB

SQL.js WASM Debug Memory - Post Mortem

Problem Description

WebAssembly compilation error in Kotlin Multiplatform web app deployed on GitHub Pages:

  • Error: CompileError: WebAssembly.instantiate(): expected magic word 00 61 73 6d, found 3c 21 44 4f @+0
  • Root cause: sqljs.worker.js file contained incorrect path locateFile:e=>"././sql-wasm.wasm" (double ./)
  • The SQLDelight web worker was trying to load WASM from an invalid path, causing 404 errors

Fix Description

Implemented robust webpack plugin with normalizeSqlJsWasmPaths function:

  • Added CopyWebpackPlugin to copy all required SQL.js files (sql-wasm.wasm, sql-wasm.js, sqljs.worker.js)
  • Created comprehensive regex patterns to fix various path formats:
    • locateFile arrow functions with any variable name
    • Relative paths (../, ./, //) and absolute paths (/)
    • Both single and double quotes
  • Applied normalization to both main compilation and distribution files
  • All paths normalized to correct ./sql-wasm.wasm format

Result

✅ WebAssembly compilation error completely resolved
✅ Note Delight web app fully functional on GitHub Pages
✅ Database operations working correctly
✅ All SQL.js components loading properly