Can not using syscall/js

hello i want to using “syscall/js”,but i get a error when i build

flb.go:5:2: build constraints exclude all Go files in C:\Go\src\syscall\js

My go version is “go1.13.5 windows/amd64”

my code as follow:

package main

import (
	"fmt"
	"syscall/js"
)

func main() {
	var cb js.Func
	cb = js.FuncOf(func(this js.Value, args []js.Value) interface{} {
		fmt.Println("button clicked")
		cb.Release() // release the function if the button will not be clicked again
		return nil
	})
	js.Global().Get("document").Call("getElementById", "myButton").Call("addEventListener", "click", cb)
}

please help me fix it , and i’m really sorry for my poor English

How are you compiling?

Using that package will obviously work only when you compile to JavaScript or WASM.

hello , this is my build script

SET GOOS=js
SET GOARCH=wasm
go build  -o flb.wasm fib.go

and IDE have an error also please see the picture

Tell the IDE to build for correct OS and ARCH, it probably tries to compile and analyze in the context of your host.

At least if building from the terminal like described above works without an error, then changing the IDEs target context should help.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.