When developing golang webassembly in vscode, an error is reported when importing the package. The code is as follows:
// main.go
package main
import "syscall/js"
func main() {
alert := js.Global().Get("alert")
alert.Invoke("Hello World!")
}
The error information is as follows:
could not import syscall/js (cannot find package "syscall/js" in any of
E:\Go\src\syscall\js (from $GOROOT)
F:\go\Gopath\src\syscall\js (from $GOPATH))
error while importing syscall/js: build constraints exclude all Go files in E:\Go\src\syscall\js
The solution is as follows:
Open setting and enter go tools env
Open settings.JSON file, write in the file:
{
"go.toolsEnvVars": {
"GOOS":"js",
"GOARCH":"wasm"
}
}
Then reopen vscode.