Open owenwaller opened 4 weeks ago
Make sure you copy wasm_exec.js to your runtime environment.
Via https://tinygo.org/docs/guides/webassembly/wasm/
Also note that the TinyGo wasm_exec.js file is different from the "big Go" file.
Hope that helps!
@deadprogram
Ah ha, that is indeed the problem. If I swap the wasm_exec.js
for the one currently on the master branch:
https://github.com/tinygo-org/tinygo/blob/release/targets/wasm_exec.js
Then all is good using with tinygo v 0.32.0
. Well spotted, thank you.
Is there any thing the tinygo
team can do to spit this sort of mistake at runtime? Or at least make the error message meaningful?
Updated to add:
A similar situation exists with the standard Go compiler i.e. the version of wasm_exec.js
must match the version of the compiler.
But, given a wasm_exec.js
e.g. one that is committed to a repository, it is impossible to tell if that version of wasm_exec.js
is compatible with the local Go toolchain.
I have raised this on the golang-nuts
mailing list, along with a proposed solution - to embed a version string as a comment into wasm_exec.js
See:
https://groups.google.com/g/golang-nuts/c/XJuEayu2KmE
Could the tinygo
team please comment on this, and also consider a similar solution, or follow whatever solution to Go project uses?
Thanks
Owen
Hi,
Can someone please clarify the level of support provided by tinygo (v0.32.0 - which is the latest AFAIK) with respect to a wasm target that is being executed in a browser, in comparison to Go v1.22.6.
I can currently seeing very different behaviour when I compile a trivial Go file to wasm using both compilers.
When I compile the Go code with
tinygo
I see the following error message in the browser console:However if I compile the same code with Go v 1.226 and server it with the same web server (nginx in a container in my case) the wasm code works as I expect.
Is this a bug in
tinygo
? I am using the dockerised version oftinygo
if that's any help.Steps to reproduce
main.go
index.html
The
go.mod
is:The
wasm_exec.js
is taken fromgo env GOROOT
/misc/wasm/wasm_exec.js`. This is my Go v1.22.6 root.The
tinygo
build cmd is:executed in the the directory where the source code is, so the volume map works.
The standard Go build cmd is:
Again from the directory that contains the source code.
The resulting
main.wasm
is then served using a standardnginx
container like this:Again from the directory that contains the source code.
If I serve the
main.wasm
build with the standard Go v1.22.6 compiler I seeWasm hello
in the browser console. If I serve the version built withtinygo
I see the uncaught promise error.This is 100% reproducible, as far as I can tell.
Does anyone have any idea of the cause and is there a fix?
Many thanks
Owen
~Updated to add: I see the same behaviour is I use Go v 1.23 in comparison to
tinggo v0.32.0
.~ So with go 1.23 nothing works. I had a old (read go 1.22.6) module cache locally and an outdated `go.mod that specified go v1.22.6.If I update the
go.mod
to:I then see this when I attempt to build:
So that looks like Go v1.23 support isn't in place yet.
Updated to add: if I use the bleeding edge docket image
tinygo/tinygo-dev@latest
I still see the same uncaught exception error in the browser window. Again against Go v1.23. But in addition I now see this on the command like:The warning is new, and as you can see from the
docker
command the volume mapping now requires mapping into/go
on the container (it was/home/tinygo
).