Can't Run TS Example from 0.8 Release Blog
rawkode opened this issue · 2 comments
rawkode commented
> @ build /Users/rawkode/Code/src/github.com/RawkodeAcademy/exploring-webassembly-with-spin/whats-new-0.8/js-routing
> pnpm exec webpack --mode=production && mkdir -p target && spin js2wasm -o target/spin-http-js.wasm dist/spin.js
asset spin.js 4.94 KiB [compared for emit] (name: main)
runtime modules 670 bytes 3 modules
./src/index.ts 3.23 KiB [built] [code generated]
webpack 5.75.0 compiled successfully in 554 ms
thread '<unnamed>' panicked at 'called `Result::unwrap()` on an `Err` value: Uncaught TypeError: not a function
at <anonymous> (script.js:79)
at <eval> (script.js:106)
', crates/spin-js-engine/src/lib.rs:440:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Error: the `wizer.initialize` function trapped
Caused by:
wasm trap: wasm `unreachable` instruction executed
wasm backtrace:
0: 0xf949e - panic_abort::__rust_start_panic::abort::h052802d600e030ed
at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/panic_abort/src/lib.rs:83:17
- __rust_start_panic
at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/panic_abort/src/lib.rs:37:5
Error: Couldn't create wasm from input
ELIFECYCLE Command failed with exit code 1.
import { HandleRequest, HttpRequest, HttpResponse } from "@fermyon/spin-sdk";
const encoder = new TextEncoder();
const router = utils.Router();
router.get("/", (req) => {
return {
status: 200,
body: encoder.encode(`Hello, Spin! Handling route ${req.url}`).buffer,
};
});
router.get("/goodbye", ({ params }): HttpResponse => {
return {
status: 200,
body: encoder.encode("Goodbye").buffer,
};
});
// handleRequest is the entrypoint to the Spin handler.
export const handleRequest: HandleRequest = async function (
request: HttpRequest,
): Promise<HttpResponse> {
return await router.handleRequest(request);
};
karthik2804 commented
Make sure to update the js2wasm
plugin (v0.3.0) using the following commands:
$ spin plugin update
$ spin plugin upgrade js2wasm
$ spin js2wasm -V
js2wasm 0.3.0
rawkode commented
Thanks!