How to Use Go Wasm with WASI (WebAssembly System Interface)

Web
Go does not support WASI with the js/wasm target; use GOOS=wasip1 GOARCH=wasm to compile for WASI instead.

You cannot use WASI with Go's js/wasm target because the Go compiler only supports the browser environment for WebAssembly. The js/wasm build target (GOOS=js GOARCH=wasm) generates code that relies on browser JavaScript glue code and does not support system calls required by WASI. To run Go on WASI, you must use the wasm/wasi target instead. Run the following command to compile your Go program for WASI:

GOOS=wasip1 GOARCH=wasm go build -o main.wasm main.go