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

syscall/js: Wasm build in docker resulted in error gojs error is not object or function #61982

Closed
sujit-baniya opened this issue Aug 12, 2023 · 3 comments

Comments

@sujit-baniya
Copy link

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

1.21

$ go version

Does this issue reproduce with the latest release?

Yes

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

Linux Intel and Mac Silicon

go env Output
$ go env

What did you do?

I tried to build the wasm binary in Dockerfile to be used by React frontend. For the purpose I build a Dockerfile with following content.

FROM golang:alpine as go
WORKDIR /app
COPY ./wasm .
RUN go mod tidy && GOOS=js GOARCH=wasm go build -ldflags="-w -s" -o main.wasm

FROM node:alpine as web
RUN npm install -g pnpm
WORKDIR /app
COPY package.json .
COPY package-lock.json .
RUN pnpm install
COPY . .
RUN pnpm build:ts

FROM nginx:latest
WORKDIR /usr/share/nginx/html
RUN rm -rf ./*
COPY --from=web /app/build .
COPY --from=go /app/main.wasm .
ENTRYPOINT ["nginx", "-g", "daemon off;"]

Resource: https://github.com/sujit-baniya/react-app-typescript-golang/blob/master/Dockerfile

Then running the commands

docker compose build && docker compose up -d

What did you expect to see?

I expected to see the working version of application and don't see any error.

What did you see instead?

I see error on browser when visiting the application on browser

Uncaught (in promise) TypeError: WebAssembly.instantiate(): Import #0 module="gojs" error: module is not an object or function

@seankhliao
Copy link
Member

your wasm_exec.js doesn't line up with the one we distribute https://github.com/golang/go/blob/go1.21.0/misc/wasm/wasm_exec.js#L216

@seankhliao seankhliao closed this as not planned Won't fix, can't repro, duplicate, stale Aug 12, 2023
@sujit-baniya
Copy link
Author

sujit-baniya commented Aug 12, 2023

@seankhliao Can we move this to discussion as it's throwing error on following:

src/LoadWasm/wasm_exec.js
  Line 14:8:    'globalThis' is not defined  no-undef
  Line 16:5:    'globalThis' is not defined  no-undef
  Line 61:8:    'globalThis' is not defined  no-undef
  Line 62:5:    'globalThis' is not defined  no-undef
  Line 76:8:    'globalThis' is not defined  no-undef
  Line 80:8:    'globalThis' is not defined  no-undef
  Line 84:8:    'globalThis' is not defined  no-undef
  Line 88:8:    'globalThis' is not defined  no-undef
  Line 95:3:    'globalThis' is not defined  no-undef
  Line 241:13:  'fs' is not defined          no-undef
  Line 477:9:   'globalThis' is not defined  no-undef
  Line 486:10:  'globalThis' is not defined  no-undef

Search for the keywords to learn more about each error.

I added const globalThis = window; on the top but it still failing on

[eslint] 
src/LoadWasm/wasm_exec.js
  Line 241:13:  'fs' is not defined  no-undef

Search for the keywords to learn more about each error.

adamdecaf added a commit to moov-io/ach that referenced this issue Aug 14, 2023
@golang golang locked and limited conversation to collaborators Aug 12, 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

3 participants