Closed vexcat closed 10 months ago
Hi @vexcat, this is a known limitation and happens because the browser doesn't expose a way for finding out how many pages a WebAssembly.Memory
import requires.
You can find the full explanation, code sample, and solution in the docs: Instantiation Failed Due to Memory Import Mismatch.
The solution is to give runWasix()
the *.wasm
file's bytes and let it handle the module compilation. We have a polyfill which will manually parse the *.wasm
file and extract the information needed to properly instantiate the WebAssembly module.
const response = await fetch("/rayon-threads.wasm");
const wasm = await response.arrayBuffer();
const instance = await runWasix(wasm);
...
Hi, thanks for the response.
let wasmReq = await fetch('/rayon-threads.wasm');
let wasmArr = new Uint8Array(await wasmReq.arrayBuffer());
let instance = await runWasix(wasmArr, {});
This does not work either, failing with the same error. Maybe this is a recent regression?
@vexcat did you solve this? Getting the same problem @Michael-F-Bryan
Unfortunately, I left Wasmer at the end of January and am no longer working on any Wasmer projects. @syrusakbary should be able to help you, though.
I ran into the same issue. Building wasmer-js
locally solved it for me. Perhaps the package needs to be updated on npm?
Hey @vexcat, @argenisleon we are upgrading the SDK on this PR: https://github.com/wasmerio/wasmer-js/pull/424
Let me know if using wasmer-js from the branch solves things for you
It looks like I modified something in my cache at some point, which is why it appeared a local build worked for me. I was able to reproduce the issue with a fresh cache, and with the npm rc from yesterday.
It looks like the problem is From<WebAssembly::Module> for Module
removes type hints in wasmer here.
That's called from From<WebAssembly::Module> for crate::module::Module
here, which is called when spawning a task with a module here.
runWasix
spawns a task with a module here.
If you inspect module
in src/run.rs
on lines 43 and 50, you'll see the type hints and name after creating the wasmer::Module
on 43, but not inside on the task on 50.
Attempting to run a WASIX program using
runWasix(module, {})
on @wasmer/sdk 0.6.0 fails with ok: false.Using
initializeLogger('trace');
to enable logging reveals the following:Memory import in .wasm file:
Despite this being the only memory import,
MemoryType { minimum: 1 pages, maximum: None, shared: false }
is logged, and wasmer attempts to initialize the module with only 1 page of memory.Code to reproduce: