Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
Irooniam opened this issue Jan 19, 2019 · 5 comments
Closed

Comments

@Irooniam
Copy link

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

@Irooniam Irooniam changed the title can't run test: LinkError: WebAssembly Instantiation can't run wasm module in browser: LinkError: WebAssembly Instantiation Jan 19, 2019
@agnivade
Copy link
Contributor

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.

@Irooniam
Copy link
Author

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.

@agnivade
Copy link
Contributor

dnf is not maintained by the Go team. It is recommended to download and install the distributions from the golang.org site.

@r-cohen
Copy link

r-cohen commented Jan 30, 2019

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.

@agnivade
Copy link
Contributor

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants