Skip to content

Commit eab8755

Browse files
authored
preamble.js: Don't use fetch() in Node.js environment (#16917)
Node 18 added instantiateStreaming() support, which our JS notices and tries to use together with fetch(), but fetch() does not work properly yet in Node. To avoid breakage, avoid that code path in node. Fixes #16913
1 parent 38d1292 commit eab8755

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/preamble.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1184,6 +1184,15 @@ function createWasm() {
11841184
#if ENVIRONMENT_MAY_BE_WEBVIEW
11851185
// Don't use streaming for file:// delivered objects in a webview, fetch them synchronously.
11861186
!isFileURI(wasmBinaryFile) &&
1187+
#endif
1188+
#if ENVIRONMENT_MAY_BE_NODE
1189+
// Avoid instantiateStreaming() on Node.js environment for now, as while
1190+
// Node.js v18.1.0 implements it, it does not have a full fetch()
1191+
// implementation yet.
1192+
//
1193+
// Reference:
1194+
// https://github.com/emscripten-core/emscripten/pull/16917
1195+
!ENVIRONMENT_IS_NODE &&
11871196
#endif
11881197
typeof fetch == 'function') {
11891198
return fetch(wasmBinaryFile, {{{ makeModuleReceiveExpr('fetchSettings', "{ credentials: 'same-origin' }") }}}).then(function(response) {

0 commit comments

Comments
 (0)