natemoo-re / ultrahtml

Other
523 stars 8 forks source link

`ultrahtml` crashes with bun runtime: `undefined is not an object (evaluating 't.type')` #66

Open JulianCataldo opened 10 months ago

JulianCataldo commented 10 months ago

Hello!

Reproduction repository here:

https://github.com/JulianCataldo/satori-html-bun

Steps are in the README

Works fine with tsx otherwise

JulianCataldo commented 9 months ago

Narrowing to:

import { html, parse } from "ultrahtml";

import inlineCSS from "ultrahtml/transformers/inline";

const doc = parse(html`<div>Hello world</div>`);

// THIS
const inliner = inlineCSS({ useObjectSyntax: true });

// Without `{ useObjectSyntax: true }` is fine

inliner(doc);
79 | const lastChild = (node: Node, parent?: Node) => parent?.children.filter((n: Node) => n.type === ELEMENT_NODE).pop() === node;
80 | const firstChild = (node: Node, parent?: Node) => parent?.children.filter((n: Node) => n.type === ELEMENT_NODE).shift() === node;
81 | const onlyChild = (node: Node, parent?: Node) => parent?.children.filter((n: Node) => n.type === ELEMENT_NODE).length === 1;
82 | 
83 | const createMatch = (selector: AST): Matcher => {
84 |     switch (selector.type) {
                 ^
TypeError: undefined is not an object (evaluating 'selector.type')
      at createMatch (/……………/__forks/satori-html/ultrahtml/src/selector.ts:84:13)
      at /……………/__forks/satori-html/ultrahtml/src/selector.ts:96:67
      at /……………/__forks/satori-html/ultrahtml/src/selector.ts:34:17
      at /……………/__forks/satori-html/ultrahtml/src/selector.ts:50:13
      at visit (/……………/__forks/satori-html/ultrahtml/src/index.ts:304:5)
      at visit (/……………/__forks/satori-html/ultrahtml/src/index.ts:308:9)
      at select (/……………/__forks/satori-html/ultrahtml/src/selector.ts:48:5)
      at /……………/__forks/satori-html/ultrahtml/src/transformers/inline.ts:72:21
      at /……………/__forks/satori-html/ultrahtml/test.ts:12:1

Probably an issue with parsel. Still investigating

natemoo-re commented 9 months ago

My guess would be on parsel-js being resolved incorrectly?