SteveSandersonMS / dotnet-wasi-sdk

Packages for building .NET projects as standalone WASI-compliant modules
518 stars 36 forks source link

Error while instantiating wasm file in browser environment #55

Closed dmkk3r closed 10 months ago

dmkk3r commented 1 year ago

After some time I managed to get a C# library running with the interop strategy from the Wasi.AspNetCore.Server.CustomHost. However, now an error occurs when loading the WebAssembly file in a browser: TypeError: WebAssembly.instantiate(): Import #1 module="wasi_snapshot_preview1" error: module is not an object or function w

After a quick google search I came across this link: https://stackoverflow.com/questions/67756028/why-are-there-wasi-snapshot-preview-1-imports-in-this-wasm-module with the note:

The STANDALONE_WASM flag instructs the compiler to build your module for WASI (the WebAssembly System Interface, which assumes you are not running in a browser, and interfaces with the underlying OS) - see v8.dev/blog/emscripten-standalone-wasm and bytecodealliance.org/articles/announcing-the-bytecode-alliance. If you remove the flag, your module should be compiled under the assumption it's going to get instantiated in a JavaScript runtime (browser, or Node.js).

Is there a way to get the WebAssembly file to run in the browser environment as well? My imported functions seem to show up in the WebAssembly file after I've inspected it.

HazWard commented 1 year ago

I haven't tried this but you could try using some polyfills for the imports/exports that wasi_snapshot_preview1 expects.

This (https://github.com/bjorn3/browser_wasi_shim) seems to be recommended by wasi.dev.