Reputation: 563
I am trying to integrate the dat.gui.js library into some Go code that will be compiled to webasm.
The error I get upon visiting the page is
panic: JavaScript error: this.onResize is not a function wasm_exec.js:47:14
<empty string> wasm_exec.js:47:14
goroutine 1 [running]: wasm_exec.js:47:14
syscall/js.Value.Call(0x7ff800010000000d, 0x41a038, 0x33ac7, 0x3, 0x0, 0x0, 0x0, 0x42c058, 0x0) wasm_exec.js:47:14
/usr/local/go/src/syscall/js/js.go:400 +0x34 wasm_exec.js:47:14
main.main() wasm_exec.js:47:14
/home/.../minExample.go:9 +0x3 wasm_exec.js:47:14
exit code: 2
I think I am misunderstanding something about how webasm works and don't understand why this causes errors and how to mitigate this issue. A minimal example of the error can be seen from
main.go
package main
import (
"fmt"
"syscall/js"
"time"
)
func main() {
time.Sleep(time.Second * 5) // Just in case the issue is with the library needing time to load in.
gui := js.Global().Get("dat").Call("GUI").New()
fmt.Println(gui)
}
index.html
<html>
<head>
<meta charset="utf-8">
<script src="https://cdnjs.cloudflare.com/ajax/libs/dat-gui/0.7.7/dat.gui.min.js"></script>
<script src="../wasm_exec.js"></script>
<script>
const go = new Go();
WebAssembly.instantiateStreaming(fetch("o.wasm"), go.importObject).then((result) => {
go.run(result.instance);
});
</script>
</head>
<body></body>
</html>
and running the following command
GOOS=js GOARCH=wasm go build -o o.wasm main.go
Upvotes: 0
Views: 94
Reputation: 563
The solution is to change this line
gui := js.Global().Get("dat").Call("GUI").New()
to this line
gui := js.Global().Get("dat").Get("GUI").New()
Found this through this related question JS Library dat.gui not working
Upvotes: 1