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: wasm_exec.js in Go 1.15 cannot be used alongside another JS library that overrides global.require #40730
Comments
I've not observed these errors in a recent stable version of Chrome (84.0.4147.105). I tried with Firefox 78.0a1 just now, and didn't see these errors either. I tested on macOS. |
I just tried with Chrome 84.0.4147.125, too, and got the exact same errors as with Firefox. |
Hi, I'm who requested to add line 31. And line 31 must be replaced with: if (typeof fs === "object" && Object.keys(fs).length !== 0) { |
I would similarly recommend changing line 560 to something like this: ((typeof module !== "undefined") && (global.require.main === module)) && |
I just love how workaround leads to workaround leads to workaround in the JavaScript world... But yes, I guess we can add those changes to make it more robust against weird environments. |
@neelance The "weird" environment you are mentioning here is a standard web browser. These adaptations are meant to detect the specialized environment of Node.js and enable special hooks. Anyway, I hope that in the future changes to this file will be accompanied with actual testing in the environments which it is supposed to support. |
@tliron No it is not. A standard web browser has no |
@neelance I am not using any bundler. You can see my exact usage here (see the HTML source for the page). I did some more digging and I see that the ACE library I am using is defining What is wrong with the suggested fix by @nao20010128nao ? Not only are we checking that there is a As for line 560: I am not enabling strict mode. The exception is caused because I'm personally OK patching |
@tliron Thank you for investigating further and providing additional information. Investigating and fixing an issue in Go is not possible when we can't understand and reproduce it, and your latest comment helps with that a lot. |
@tliron Nothing is wrong. I wrote above:
I was only saying that this is a very typical situation for the JavaScript world:
This is a workaround ("solve its own challenges in terms of working in different environments") leading to a workaround (add logic to detect this to wasm_exec.js). |
@neelance Thanks! I was just confused with your use of the word "weird". It seemed like you were implying that this was my fault for misusing the library. Anyway, we might not like it, but these kinds of hacky workarounds are the nature of working with web browsers. In the end this library just provides the glue so that we can use Go instead... |
Change https://golang.org/cl/248758 mentions this issue: |
I have prepared https://golang.org/cl/248758. @tliron Does this change look good? |
@neelance Thanks for asking, to me it looks fine! I also just tested it and it works in my environment. |
Confirmed it works in my environment too, go 1.15, Chrome/Firefox, but breaks without these changes. |
@neelance It looks good, and it worked in my test environment. |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
It only happens in the latest release.
What operating system and processor architecture are you using (
go env
)?go env
Output(Fedora 32)
What did you do?
Running a simple Go-compiled WASM file using wasm_exec.js inside the Firefox browser (ver 79.0).
What did you expect to see?
I expect it to work, as in the Go 1.14 version. However some changes in wasm_exec.js make it break, at least in Firefox.
What did you see instead?
Link to source code
But that's not the only issue. If I comment out the additions in line 31 I get this:
Commenting out line 560 will finally make it work.
Link to source code
See also issue #40446 which is what seems to have added line 31.
The text was updated successfully, but these errors were encountered: