fermyon / spin-js-sdk

https://developer.fermyon.com/spin/javascript-components
Apache License 2.0
52 stars 18 forks source link

Wizer failing on `marked` NPM package #280

Open technosophos opened 3 weeks ago

technosophos commented 3 weeks ago

I don't know if it is worth capturing errors like this, but..

The marked Markedown parser seems to cause a failure in Wizer or Componentize.js

Steps to reproduce:

  1. Create a new TS project
  2. npm i and then npm i marked
  3. Edit the code as shown below
  4. run spin build --up

Code:

import { ResponseBuilder } from "@fermyon/spin-sdk";
import { Marked } from "marked";

export async function handler(req: Request, res: ResponseBuilder) {
    let md = new Marked();
    res.send(await md.parse("Hello _world_"));
}

Output:

$ spin build --up                 
Building component markdowntest with `npm run build`

> markdowntest@1.0.0 build
> npx webpack --mode=production && npx mkdirp target && npx j2w -i dist.js -d combined-wit -n combined -o target/markdowntest.wasm

asset dist.js 95.6 KiB [emitted] [javascript module] (name: main)
orphan modules 109 KiB [orphan] 24 modules
./src/spin.ts + 3 modules 95.6 KiB [built] [code generated]
webpack 5.93.0 compiled successfully in 723 ms
Using user provided wit in: combined-wit
Exception while pre-initializing: (new SyntaxError("invalid class property name in regular expression", "dist.js", 939))

Error: the `componentize.wizer` function trapped

Caused by:
    0: error while executing at wasm backtrace:
           0: 0x787037 - <unknown>!<wasm function 12587>
           1: 0x7864f8 - <unknown>!<wasm function 12364>
           2: 0x4f073d - <unknown>!<wasm function 1724>
           3: 0x323ccd - <unknown>!<wasm function 517>
    1: Exited with i32 exit status 1
file:///Users/technosophos/Code/TypeScript/markdowntest/node_modules/@bytecodealliance/componentize-js/src/componentize.js:221
    throw new Error(err);
          ^

Error: Failed to initialize the compiled Wasm binary with Wizer:
Wizering failed to complete
    at componentize (file:///Users/technosophos/Code/TypeScript/markdowntest/node_modules/@bytecodealliance/componentize-js/src/componentize.js:221:11)
    at async file:///Users/technosophos/Code/TypeScript/markdowntest/node_modules/@fermyon/spin-sdk/bin/j2w.mjs:45:23

Node.js v22.6.0
Error: Build command for component markdowntest failed with status Exited(1)
technosophos commented 3 weeks ago

Similar problem with micromark

technosophos commented 3 weeks ago

But for those looking for a working Markdown processor in Spin, markdown-it works great.

tschneidereit commented 3 weeks ago

I can reproduce this with a very simple reduced test case:

addEventListener('fetch', async (event) => {
    "sdf".match(/[\p{L}\p{N}]/u);
});

Not yet sure why this fails: line 2 in that test case works in Firefox's devtools shell and in a standalone SpiderMonkey shell. Will dig in more.

tschneidereit commented 3 weeks ago

oooh, I'm pretty sure I know: StarlingMonkey doesn't currently include unicode support, because that's broken in SpiderMonkey's WASI port. Unfortunately there's little we can do about that until that problem is fixed :/