bytecodealliance / javy

JS to WebAssembly toolchain
Apache License 2.0
2.29k stars 110 forks source link

Is it possible to compile a wasm file that can be executed in HTML? #828

Closed akang1937 closed 1 week ago

akang1937 commented 1 week ago

When I compiled the file, I got two kinds of error messages like this:

1.TypeError: WebAssembly.instantiate(): Import #0 "wasi_snapshot_preview1": module is not an object or function 2.TypeError: WebAssembly.instantiate(): Imports argument must be present and must be an object

Is there a way to generate a wasm file that works fine directly in the browser. I just need to run it in the browser.

The functions in the index.js are:

function run() { console.log(123) }

run();

The way to load the module is:

fetch('add.wasm') .then(response => response.arrayBuffer()) .then(bytes => WebAssembly.instantiate(bytes)) .then(result => { result.instance.exports.run(); });

https://github.com/bjorn3/browser_wasi_shim . I've looked at this method as well, but it doesn't seem to work in pure HTML. Also, using Javy to compile JavaScript to Wasm can greatly improve performance?