Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wasm: Running the go wasm example fails using nodejs #61720

Closed
swaingotnochill opened this issue Aug 2, 2023 · 6 comments
Closed

wasm: Running the go wasm example fails using nodejs #61720

swaingotnochill opened this issue Aug 2, 2023 · 6 comments

Comments

@swaingotnochill
Copy link

swaingotnochill commented Aug 2, 2023

What version of Go are you using (go version)?

$ go version
go1.20.2 linux/amd64

Does this issue reproduce with the latest release?

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/swaingotnochill/.cache/go-build"
GOENV="/home/swaingotnochill/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/swaingotnochill/Documents/wasm/"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/swaingotnochill/Documents/"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.20.2"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/swaingotnochill/Documents/wasm/go.mod"
GOWORK=""
CGO_CFLAGS="-O2 -g"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-O2 -g"
CGO_FFLAGS="-O2 -g"
CGO_LDFLAGS="-O2 -g"
PKG_CONFIG="pkg-config"

What did you do?

What did you expect to see?

Simple "Hello World"

What did you see instead?

➜  wasm export PATH="$PATH:$(go env GOROOT)/misc/wasm"
➜  wasm GOOS=js GOARCH=wasm go run .
/usr/local/go/misc/wasm/wasm_exec_node.js:25
globalThis.crypto = {
                  ^

TypeError: Cannot set property crypto of #<Object> which has only a getter
    at Object.<anonymous> (/usr/local/go/misc/wasm/wasm_exec_node.js:25:19)
    at Module._compile (node:internal/modules/cjs/loader:1275:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1329:10)
    at Module.load (node:internal/modules/cjs/loader:1133:32)
    at Module._load (node:internal/modules/cjs/loader:972:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:83:12)
    at node:internal/main/run_main_module:23:47

Node.js v19.7.0
exit status 1

PS: I am following this example in the wiki

$ export PATH="$PATH:$(go env GOROOT)/misc/wasm"
$ GOOS=js GOARCH=wasm go run .
Hello, WebAssembly!
$ GOOS=js GOARCH=wasm go test
PASS
ok  	example.org/my/pkg	0.800s
@swaingotnochill swaingotnochill changed the title wasm: Running the go wasm example fails wasm: Running the go wasm example fails using nodejs Aug 2, 2023
@mauri870
Copy link
Member

mauri870 commented Aug 2, 2023

Seems to be an issue with newer versions of node (>=19)

$ node --version
v19.7.0

$ go version
go version go1.20.2 linux/amd64

$ export PATH="$PATH:$(go env GOROOT)/misc/wasm"
$ GOOS=js GOARCH=wasm go run .
...wasm_exec_node.js:25
globalThis.crypto = {
                  ^

TypeError: Cannot set property crypto of #<Object> which has only a getter

Node.js v19.7.0
exit status 1

$nvm use default
Now using node v16.16.0 (npm v8.11.0)

$ GOOS=js GOARCH=wasm go run .
Hello, WebAssembly!

@mauri870
Copy link
Member

mauri870 commented Aug 2, 2023

Looks like we got webcrypto on nodejs 19. It conflicts with our own definition of crypto in the wasm exec node:

https://nodejs.org/fr/blog/announcements/v19-release-announce#stable-webcrypto

@mauri870
Copy link
Member

mauri870 commented Aug 2, 2023

@seankhliao This is a bug in go and I think the fix should be included in 1.20 (if there is plan for a new hotfix), otherwise wasm on node is broken for versions newer than v19.

@mauri870
Copy link
Member

mauri870 commented Aug 2, 2023

Fixed by #56860

Fix was not ported to go 1.20

@seankhliao
Copy link
Member

given our support policy of active LTS, I don't see this qualifying for backport.

@seankhliao
Copy link
Member

Duplicate of #56860

@seankhliao seankhliao marked this as a duplicate of #56860 Aug 2, 2023
@seankhliao seankhliao closed this as not planned Won't fix, can't repro, duplicate, stale Aug 2, 2023
@golang golang locked and limited conversation to collaborators Aug 1, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants