bytecodealliance / ComponentizeJS

JS -> WebAssembly Component
Apache License 2.0
242 stars 32 forks source link

fetch globals are not available #106

Closed rebolyte closed 2 months ago

rebolyte commented 6 months ago

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?

guybedford commented 6 months ago

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!

tschneidereit commented 6 months ago

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

guybedford commented 2 months ago

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