-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Fixes #16913: Don't use fetch() in Node.js environment #16917
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
Conversation
Interesting, thanks for filing... I'd hope we can actually use |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also please add a comment, as we'd like to remove this workaround some day. Perhaps something like this:
// Avoid instantiateStreaming() on node for now, as while newer node implements it,
// it does not have a full fetch() implementation yet.
// [..link to emscripten and/or node bug..]
Done! |
What will be the path towards removing this check? It looks like there is no way to feature test what the bad Node.js versions are/will be? Does node.js have some kind of synchronous version test that could be used, e.g. "if node.js version >= x.y.z.w (regression first introduced) and node.js version < X.Y.Z.W (bugfix first appeared in), then disable streaming instantiation"? If not, it will be really hard to evolve out of this check since users of older Node.js versions might break again if this check was ever removed (after latest Node.js fixes things up)? |
We have several options.
|
E.g. something like if (!ENVIRONMENT_IS_NODE || (
versionGreaterOrEqualTo(process.versions.node, [18,1,0]) &&
versionLessThan(process.versions.node, [999,999,999]
/* TODO: When Node.js lands a fix, update version range to match accordingly*/)))
/* enable streaming instantiation */
else
/* disable streaming instantiation */ |
There is no built-in function to compare versions in Node.js, so we have to modify the code a bit much to get the behavior you want. Since applying this patch does not cause problems in future Node.js versions, why don't we discuss the issue of removing this patch again in another PR or another issue? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense to me to land this, and consider improvements later.
emscripten/emsdk 3.1.13 (2022-06-04) にて修正済 cf. emscripten-core/emscripten#16917
emscripten/emsdk 3.1.13 (2022-06-04) にて修正済 cf. emscripten-core/emscripten#16917
emscripten/emsdk 3.1.13 (2022-06-04) にて修正済 cf. emscripten-core/emscripten#16917
FWIW, out of curiosity, I tried to use streaming compilation with manual conversion from Node.js file streams, and it does work, but is ~2x slower than the buffer-based variant: https://twitter.com/RReverser/status/1593330290491068416 It's said to be due to the current implementation of Web streams in Node being experimental and not optimised yet, so it might change in the future, but, at least, for now there is no advantage in using streaming compilation. |
Thanks for the research @RReverser! Looks like we'd be better to sustain this patch for a long time in that case. |
Node.js v18.1.0 has implemented
WebAssembly.instantiateStreaming
API, and it broked all emscriptened js codes since emscripten is usingWebAssembly.instantiateStreaming
as a criterion to distinguish whether it is Node.js environment or a browser environment.The issue will be fixed if we use
ENVIRONMENT_IS_NODE
as a proper criterion to distinguish Node.js environment.Fixes #16913, antelle/argon2-browser#81.
References
WebAssembly.instantiateStreaming
in v18.1.0 #16913