Skip to content

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

@Irooniam

Description

@Irooniam

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions