go version)?> go version go version go1.11.2 linux/amd64
I don't know yet. All the example code I've seen runs on go 1.11
go env)?go env Output
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/bob/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/bob/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/lib/golang"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/golang/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build169530480=/tmp/go-build -gno-record-gcc-switches"
I tried following various example of how to get a wasm module compiled via golang to work in the browser, primarily: https://github.com/golang/go/wiki/WebAssembly
hello.go
package main
import (
"fmt"
)
func main() {
fmt.Println("hello world")
}
Compiled into wasm module via:
GOOS=js GOARCH=wasm go build -o hello.wasm hello.goI then copied the js / html fiels for running wasm in browser via: https://github.com/golang/go/tree/master/misc/wasm Lastly, I created simple http server to serve up the assets:
~/go/bin/goexec 'http.ListenAndServe(":8080", http.FileServer(http.Dir(".")))'
I expected to see a active button, so that when clicked it was display "hello world" in the browser console
Uncaught (in promise) LinkError: WebAssembly Instantiation: Import #5 module="go" function="runtime.scheduleCallback" error: function import requires a callable
I then copied the js / html fiels for running wasm in browser via:
https://github.com/golang/go/tree/master/misc/wasm
Do not copy from master branch. Use the files from your distribution as mentioned in the wiki page.
$ cp "$(go env GOROOT)/misc/wasm/wasm_exec.js" . and same for the html file.
If the issue still persists after you have copied the correct files, please let us know.
Thanks much for the suggestion.
I copied the relevant files from the release-branch.go1.11 branch and it works as advertised.
Just as an aside, I'm using Fedora 29 and though I used dnf to install go, my GOROOT doesn't have any of the wasm related files for whatever reason.
dnf is not maintained by the Go team. It is recommended to download and install the distributions from the golang.org site.
had the same issue, also using Fedora 29, my GOROOT has no wasm related files, and it's Go 1.11. just thought someone should know.
I do not know much about dnf. It is not clear if you are talking about dnf or the Go distribution from the website. If you are not seeing any wasm related files in your GOROOT after un-tarring your gzip file from the golang.org site, please open a new issue.
Most helpful comment
Do not copy from master branch. Use the files from your distribution as mentioned in the wiki page.
$ cp "$(go env GOROOT)/misc/wasm/wasm_exec.js" .and same for the html file.If the issue still persists after you have copied the correct files, please let us know.