{"id":25715,"library":"h2x-core","title":"h2x-core","description":"h2x-core is the core compiler for h2x, an HTML-to-JSX transformer. It converts HTML strings into a JavaScript AST (JSX) via JSDOM, using a plugin system for extensibility. Version 1.1.1 is current, with releases every few months. Key differentiators: leverages JSDOM for robust parsing, supports state, and has a plugin architecture. It handles special SVG attributes and style attributes. Alternatives are typically SVGR or manual transformation.","status":"active","version":"1.1.1","language":"javascript","source_language":"en","source_url":"https://github.com/smooth-code/h2x/tree/master/packages/h2x-core","tags":["javascript"],"install":[{"cmd":"npm install h2x-core","lang":"bash","label":"npm"},{"cmd":"yarn add h2x-core","lang":"bash","label":"yarn"},{"cmd":"pnpm add h2x-core","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"provides node type definitions","package":"h2x-types","optional":false},{"reason":"used to parse HTML into a DOM tree for AST generation","package":"jsdom","optional":false}],"imports":[{"note":"Use ESM import. CommonJS require also works but is less common.","wrong":"const { compile } = require('h2x-core')","symbol":"compile","correct":"import { compile } from 'h2x-core'"},{"note":"The correct function name is 'transform', not 'transpile'.","wrong":"import { transpile } from 'h2x-core'","symbol":"transform","correct":"import { transform } from 'h2x-core'"},{"note":"Direct 'parse' export. No submodule import.","wrong":"import { parseHtml } from 'h2x-core'","symbol":"parse","correct":"import { parse } from 'h2x-core'"}],"quickstart":{"code":"import { compile } from 'h2x-core';\nimport pluginJsx from 'h2x-plugin-jsx';\n\nconst html = `<div class=\"foo\">Hello</div>`;\nconst jsx = compile(html, {\n  plugins: [pluginJsx],\n  output: 'string'\n});\nconsole.log(jsx); // <div className=\"foo\">Hello</div>","lang":"typescript","description":"Demonstrates how to compile HTML to JSX using a plugin."},"warnings":[{"fix":"Update code to use new API: node.originalNode, fromHtmlAttribute, fromHtmlElement.","message":"v1.0.0: AST generation changed from a custom tree to JSDOM-based tree. You must use fromHtmlAttribute and fromHtmlElement for node replacement. originalNode property available.","severity":"breaking","affected_versions":">=1.0.0 <1.2.0"},{"fix":"Install and pass plugins: e.g., `compile(html, { plugins: [require('h2x-plugin-jsx')] })`.","message":"The package does not include any default plugin; you must provide plugins (e.g., h2x-plugin-jsx) for meaningful output.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Ensure jsdom >=12 is installed.","message":"JSDOM v12+ required; older JSDOM versions may cause parse errors.","severity":"gotcha","affected_versions":">=1.1.0"},{"fix":"Update to v1.x API (compile, transform, parse).","message":"In v0.x, the API exported a different set of functions. Direct migration may break.","severity":"deprecated","affected_versions":"<1.0.0"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Run `npm install h2x-core` and ensure import path is correct: `import { compile } from 'h2x-core'`.","cause":"h2x-core not installed or not imported correctly.","error":"Error: Cannot find module 'h2x-core'"},{"fix":"Use named import: `import { compile } from 'h2x-core'`.","cause":"Mis-imported default export vs named export.","error":"TypeError: compile is not a function"},{"fix":"Run `npm install jsdom@12`.","cause":"jsdom peer dependency not installed.","error":"Error: JSDOM is not defined"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}