Load WASI module from local wasm file?

Hi everyone,

I’m trying to load a WASI module compiled with WASI-SDK from a local wasm file, using examples from this repository. I can easily compile and load these examples without using stdlib, e.g. for ‘example1.c’:

addTwoInts = {
    const buf = await FileAttachment("./example1.wasm").arrayBuffer();
    // Create a WebAssembly instance from the wasm.
    const res = await WebAssembly.instantiate(buf, {});
    // Get the function to call.
    const { addTwoInts } = res.instance.exports;

However, for more elaborate examples, I’d like to use libc. However, when I used modules compiled using WASI-SDK, I get the following error:

TypeError: WebAssembly.instantiate(): Import #0 module="env" error: module is not an object or function

Is there a WASI module loader that works in Observable with local wasm files?

1 Like

Can you share an example notebook that has your compiled modules attached?

try this with

addTwoInts = {
  const { WebAssembly } = window,
    buf = await FileAttachment("./example1.wasm").arrayBuffer(),
    module = new WebAssembly.Module(buf),
    instance = new WebAssembly.Instance(module, {});
  return instance.exports;
1 Like