kajacx / wasm-bridge

Provides a single unified API to run WASM modules on the desktop using wasmtime, or on the web using js-sys.
MIT License
46 stars 7 forks source link

Web failing to instantiate #16

Open kayhhh opened 2 months ago

kayhhh commented 2 months ago

I have a simple schema:

package example:schema;

world my-world {
  export my-interface;
}

interface my-interface {
  resource my-res {
    constructor();
    my-method: func(value: f32);
  }
}

I am able to use it in native builds, but run into an error with the web build: Asynchronously instantiate main module TypeError: import object field '[export]example:schema/my-interface' is not an Object

Full code: https://github.com/kayhhh/wasm-bridge-example/tree/5e9165141f47344b75b82644f63f5db0430fcaed

I have gotten some of the test examples in this repo working, but with certain schemas like this I get errors.

kayhhh commented 2 months ago

Hmm, working backwards from a working example, it looks like the following WIT is good:

package component-test:wit-protocol;

interface companies {
  resource company-res {
    constructor(name: string, max-salary: u32);
    get-name: func() -> string;
    set-name: func(name: string);
    get-max-salary: func() -> u32;
  }
}

interface employees {
  resource employee-res {
    constructor(name: string, min-salary: u32);
    get-name: func() -> string;
    set-name: func(name: string);
    get-min-salary: func() -> u32;
  }
}

world resources {
  import companies;

  export employees;

  import log: func(message: string);
}

But if I remove import companies from resources, and its associated host implementation, I start getting the same not an Object error in web.