I am trying to load sql-wasm.wasm from https://github.com/sql-js/sql.js such that it does not need a server. Otherwise, trying to load wasm from HTML gives CORS error. I converted it to base64 (~800KB) which looks like this
const SQLBASE64 = "AGFzbQEAAAABrQRHYAJ/fwF/YAF/AX....AAJ4BAEHwogQLA4AWUQ==";
(link to full base64 string)
WebAssembly.Instance
only works with very small binaries. WebAssembly.instantiate()
and WebAssembly.instantiateStreaming()
both end up with errors about incorrect object, format, or headers etc.
How do I do it properly?
2
Answers
So there were two problems.
sql-wasm.wasm v1.8.0
to base64 correctly.WebAssembly.instantiate
directly, useinitSqlJs()
from sql.js instead.Then loaded it like this
Base64 wasm gist https://gist.github.com/SMUsamaShah/358fba159cb41fe469fc61e7db444c0e
You can try using the answer from this question (with your
const
it would be):Edit:
I investigated more, and you need the
sql-wasm.js
file in order to instantiate thesql-wasm.wasm
file. Your wasm module needs imports thatsql-wasm.js
would give, but the config it takes seems to only take a path, for now. Meaning, there is no way to tell it to load a binary module already in the html file.I think this can be changed though, with either a pull request or an issue on the official repo. I am, of course, hopeful to be proven wrong by somebody more knowledgeable.