Regression in fetch-event example using jco 1.10.2 and componentize-js 0.18.0
I had the following example working correctly with jco 1.9.1, componentize-js 0.16.0, wasmtime 31.0.0 in a WSL 2 ubuntu linux environment:
{
const { addEventListener } = globalThis;
addEventListener(
"fetch", (event) =>
event.respondWith(
(async () => {
try {
console.log('start httpbin request');
const request = await fetch('https://httpbin.org/json');
const result = await request.text();
console.log('finish httpbin request');
return new Response(`Hello from TypeScript!, result: ${result}`);
} catch (e) {
console.error(e);
return new Response('whoopsies');
}
})(),
),
);
}
I could build the example, run with wasmtime serve --addr 0.0.0.0:8000 -S cli=y dist/main.wasm and see output like the following when visited in the browser:
Hello from TypeScript!, result: {
"slideshow": {
"author": "Yours Truly",
"date": "date of publication",
"slides": [
{
"title": "Wake up to WonderWidgets!",
"type": "all"
},
{
"items": [
"Why <em>WonderWidgets</em> are great",
"Who <em>buys</em> WonderWidgets"
],
"title": "Overview",
"type": "all"
}
],
"title": "Sample Slide Show"
}
}
When I upgrade to jco 1.10.2, componentize-js 0.18.0, and keep the same wasmtime 31.0.0 in a WSL 2 ubuntu linux environment I get the following console error when visiting the endpoint with wasmtime serve:
> wasmtime serve --addr 0.0.0.0:8000 -S cli=y dist/main.wasm
Serving HTTP on http://0.0.0.0:8000/
2025-04-02T02:30:26.260665Z ERROR wasmtime_cli::commands::serve: [0] :: error while executing at wasm backtrace:
0: 0x80fb90 - <unknown>!environ_sizes_get
1: 0x775799 - <unknown>!<wasm function 12652>
2: 0x7a05be - <unknown>!<wasm function 12889>
Caused by:
wasm trap: wasm `unreachable` instruction executed
error: hyper::Error(User(Service), guest never invoked `response-outparam::set` method
Caused by:
0: error while executing at wasm backtrace:
0: 0x80fb90 - <unknown>!environ_sizes_get
1: 0x775799 - <unknown>!<wasm function 12652>
2: 0x7a05be - <unknown>!<wasm function 12889>
1: wasm trap: wasm `unreachable` instruction executed)
I created a successful reproduction and a failing reproduction. In both examples:
-
npm install -
npm run build -
npm run start-wasmtime - Visit
localhost:8000in the browser
The stack trace in the repro linked from the following issue looks very similar, might be the same issue? https://github.com/bytecodealliance/ComponentizeJS/issues/194#issue-2874617224
It appears to be the same issue. The workaround right now is to include the wasi:cli/[email protected] as an import on the target wit world.
Thanks @karthik2804! Updating the wit in the above examples to:
package main-namespace:main-package;
world main-world {
import wasi:cli/[email protected];
export wasi:http/[email protected];
}
unblocked me from upgrading to @bytecodealliance/[email protected] and @bytecodealliance/[email protected] 🎉
Hey @rajsite incredibly late here, but yes -- this is partially why we haven't upgraded to 0.18.0 at present (our examples also break in CI), there were also some other problems (for which a fix has now been merged) -- we're waiting on a release of componentize-js as well :)
Once we're able to get jco updated to componentize-js to 0.18.3 (or whatever the new version ends up being), I'll close this out.
This has been fixed with the latest jco, componentize-js and underlying StarlingMonkey releases.
While StarlingMonkey does not yet support fetch-event being called multiple times in a row IIRC, and Jco still reuses components between requests, wasmtime serve should work fine now for JS components (since it does not reuse components).