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

Open
Mikerah opened this issue Nov 21, 2019 · 3 comments

Comments

@Mikerah
Copy link

@Mikerah 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

This comment has been minimized.

Copy link
Member

@bradfitz bradfitz commented Nov 21, 2019

/cc @neelance

@neelance

This comment has been minimized.

Copy link
Member

@neelance neelance commented Nov 23, 2019

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

This comment has been minimized.

Copy link
Author

@Mikerah 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.