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.
Read More:
- [Solved] Error running ‘go build myfir_go_project‘: Cannot run program
- Webpack Pack and compress ES6 files with errors: ERROR in js/xxxxxx.js from UglifyJs Unexpected token punc ()
- [Solved] Golang Error: main.go:5:2: package go_code/chapter10/factory/model is not in GOROOT
- VScode jsconfig.json files First Line error for no reasons
- Flutter android studio runs gradle build error: Could not resolve all artifacts for configuration’:classpath’.
- Go build package error: TARGET_OS_MAC & IOMasterPort
- vscode: Error loading workspace: err: exit status 1: stderr: build flag -mod=readonly only valid
- [Solved] ionic Build Error: Cannot load gulp tasks: Error: Error in module: .\gulpfile.js:
- [Solved] cannot find package “go.opentelemetry.io/otel/api/trace“ in any of
- [Solved] .\main.go:3:6: missing function body .\main.go:4:1: syntax error: unexpected semicolon or newline be
- [Solved] Unity Publish WebGL Error: Unable to parse Build/webTest2.framework.js.gz
- Go declares that the local variable does not use command line arguments. Main. Go: 4:6: a declared but not used
- VScode: How to Solve golong plug-in install Error
- [Solved] ORA-21525: attribute number or (collection element at index) string violated its constraints
- [Solved] Vscode error: Unable to resolve resource walkThrough://vscode_getting_started_page
- [GO] The entry file under the main package in golang calls other go file functions and appears undefined
- [Solved] VScode Error: PS D:\vscode> cd “d:\vscode\“ ; if ($?) { g++ tempCodeRunnerFile.cpp -o tempCodeRunn
- Go Language Error: main redeclared in this block [How to Solve]
- [Solved] LibreSSL SSL_connect: SSL_ERROR_SYSCALL in connection to github.com:443
- [Solved] Unity Package Error: Failed running D:\Program Files\Unity2018.4.1\Editor\Data\il2cpp/build/il2cpp.exe