Go: can't run wasm module in browser: LinkError: WebAssembly Instantiation

Created on 19 Jan 2019  路  5Comments  路  Source: golang/go

What version of Go are you using (go version)?

> go version
go version go1.11.2 linux/amd64

Does this issue reproduce with the latest release?

I don't know yet. All the example code I've seen runs on go 1.11

What operating system and processor architecture are you using (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"

What did you do?

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.go
I 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(".")))'

What did you expect to see?

I expected to see a active button, so that when clicked it was display "hello world" in the browser console

What did you see instead?

Uncaught (in promise) LinkError: WebAssembly Instantiation: Import #5 module="go" function="runtime.scheduleCallback" error: function import requires a callable

FrozenDueToAge

Most helpful comment

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.

All 5 comments

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

chai2010 picture chai2010  路  216Comments

tklauser picture tklauser  路  219Comments

ianlancetaylor picture ianlancetaylor  路  519Comments

derekperkins picture derekperkins  路  180Comments

bradfitz picture bradfitz  路  176Comments