#5559·cheerio

prop(style) throws for text, comment and document nodes

Author: xu91102Created Sep 26, 2026Updated Sep 26, 2026

Reading .prop('style') on a text, comment, or document node throws TypeError: Cannot convert undefined or null to object. Other element-only property getters return undefined on these nodes, and .css() already returns undefined.

javascript
const $ = load('<div>text<!--comment--></div>');
$('div').contents().first().prop('style'); // throws
$.root().prop('style');                  // throws

Expected: undefined, as for an absent style property, rather than a crash while enumerating the undefined result of .css().

Reproduced against main 0ab9a8e943bb86704ceb962770bc46647404ea45 with the existing attributes Vitest suite. Proposed fix: apply the same element guard used by the adjacent tagName/href getters before constructing style properties.

Investigated with OpenAI Codex assistance on macOS / Node.js.