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

misc/wasm: using wasm_exec.js in a NodeJs project #35729

Closed
Mikerah opened this issue Nov 21, 2019 · 4 comments
Closed

misc/wasm: using wasm_exec.js in a NodeJs project #35729

Mikerah opened this issue Nov 21, 2019 · 4 comments
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Milestone

Comments

@Mikerah
Copy link

Mikerah commented Nov 21, 2019

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

$ go version
go1.13.4 linux/amd64

Does this issue reproduce with the latest release?

Yes

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

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/mikerah/snap/code/common/.cache/go-build"
GOENV="/home/mikerah/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/mikerah/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build686789620=/tmp/go-build -gno-record-gcc-switches"

What did you do?

I'm currently trying to use wasm_exec.js in a nodejs project. The way I am importing the file into my project is by using the require statement i.e. const wasm_exec = require("./wasm_exec.js").

What did you expect to see?

Nothing. This program doesn't print to standard output.

What did you see instead?

The following error
.../wasm_exec.js:85 }console.log(fetch); ^ ReferenceError: fetch is not defined
It seems like this file is choosing the wrong environment and is seeking the browser environment instead of the nodejs environment.

@bradfitz bradfitz changed the title Using wasm_exec.js in a NodeJs project misc/wasm: using wasm_exec.js in a NodeJs project Nov 21, 2019
@bradfitz
Copy link
Contributor

/cc @neelance

@bradfitz bradfitz added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Nov 21, 2019
@bradfitz bradfitz added this to the Go1.14 milestone Nov 21, 2019
@neelance
Copy link
Member

fetch is not referenced by the wasm_exec.js on master. Your error message looks like you have a line }console.log(fetch); in your version of wasm_exec.js.

If you're planning to use net/http package, which requires fetch, then you should use a polyfill like https://www.npmjs.com/package/node-fetch.

@Mikerah
Copy link
Author

Mikerah commented Nov 23, 2019

I have go version go1.13.4 linux/amd64 installed. However, looking through this repo, I see that I indeed have a different version of wasm_exec.js than the one in this repo. I will attempt to simply clone this repo and copy the wasm_exec.js file from the repo into my project and see if it fixes anything.

@agnivade agnivade added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Nov 25, 2019
@ianlancetaylor ianlancetaylor modified the milestones: Go1.14, Backlog Dec 5, 2019
@gopherbot
Copy link

Timed out in state WaitingForInfo. Closing.

(I am just a bot, though. Please speak up if this is a mistake or you have the requested information.)

@golang golang locked and limited conversation to collaborators Dec 24, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

6 participants