ComponentizeJS icon indicating copy to clipboard operation
ComponentizeJS copied to clipboard

fetch globals are not available

Open rebolyte opened this issue 1 year ago • 2 comments

I see in the tests that the global Request/Response/Headers objects are available, and I can create Headers successfully. But if I try to create Request or Response using the example, the module errors out with wasm 'unreachable' instruction executed:

diff --git a/example/hello.js b/example/hello.js
index 8671f41..fde2ac6 100644
--- a/example/hello.js
+++ b/example/hello.js
@@ -1,3 +1,11 @@
 export function hello (name) {
+  // const headers = new Headers();
+
+  const req = new Request('http://httpstat.us/200', {
+    method: 'GET',
+  });
+
+  // const res = new Response();
+
   return `Hello ${name}`;
 }

If I return Reflect.ownKeys(globalThis).join(',') from the function, I can see also see they're on the object. My end goal is to be able to run Hono inside the module, and it uses the native req/res objects. What am I missing?

rebolyte avatar May 17 '24 01:05 rebolyte

Yes, this is a duplicate of https://github.com/bytecodealliance/ComponentizeJS/issues/96, which has root cause https://github.com/bytecodealliance/StarlingMonkey/issues/19.

It's not being actively worked on because the StarlingMonkey consumers all have a custom implementation, which is very unfortunate for adoption I know!

guybedford avatar May 17 '24 01:05 guybedford

I am, slowly, working on the upstream bug, fwiw. It's a surprisingly big change to make fetch work properly, but it is coming ☺️

tschneidereit avatar May 17 '24 10:05 tschneidereit

Fixed in https://github.com/bytecodealliance/ComponentizeJS/pull/131.

guybedford avatar Aug 28 '24 18:08 guybedford