Registry / serialization / html-to-jsx

html-to-jsx

JSON →
library0.0.4jsnpmunverified

html-to-jsx is a lightweight, regex-based compiler that converts HTML strings into JSX syntax suitable for React applications. Version 0.0.4 is the latest stable release, though the package has seen no updates since its initial publication, indicating maintenance is stagnant. It differentiates from alternatives like html-react-parser by operating purely with regex without DOM parsing, making it fast but potentially brittle for complex or malformed HTML. The package is minimal, offering no TypeScript types, and is intended for simple conversion tasks where full HTML spec compliance is not required.

npm install html-to-jsx
INSTALL
IMPORT
SIG · HTML-TO-JSX
H
html-to-jsx
serializationjavascriptv0.0.4
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
import htmlToJsx from 'html-to-jsx'
const htmlToJsx = require('html-to-jsx')
The package is ESM-compatible but the default export is a function that expects a string input.
htmlToJsx
const { htmlToJsx } = require('html-to-jsx')
import { htmlToJsx } from 'html-to-jsx'
In CommonJS environments, the export is an object with a single method; named ESM import is incorrect.
type import
// No type exports available
import type { Options } from 'html-to-jsx'
The package does not ship TypeScript definitions or type exports.

Converts a simple HTML string with class attribute to JSX className syntax.

import htmlToJsx from 'html-to-jsx'; const html = '<div class="container"><p>Hello World</p></div>'; const jsx = htmlToJsx(html); console.log(jsx); // Expected output: <div className='container'><p>Hello World</p></div>
html-to-jsx --version
Debug
Known issues
gotchaRegex-based parsing: does not handle nested or complex HTML structures correctly.
fix
Use a proper HTML parser-based library (e.g., html-react-parser) for reliable conversion of complex HTML.
affects: >=0.0.0
gotchaSelf-closing tags conversion: may not convert all self-closing tags (e.g., <br>, <img>) correctly in all contexts.
fix
Manually verify converted JSX for self-closing tags, or add trailing slashes in input HTML.
affects: >=0.0.0
deprecatedPackage is unmaintained; no updates since 2015.
fix
Consider migrating to actively maintained alternatives like html-react-parser or dangerouslySetInnerHTML.
affects: >=0.0.0
gotchaDoes not digest features like inline events, React Fragments, or JSX expressions.
fix
Preprocess HTML to remove/replace unsupported features before conversion, or use a more comprehensive tool.
affects: >=0.0.0
Errors
Common errors & fixes
Cannot find module 'html-to-jsx'
Package not installed or missing from dependencies.
fix
Run `npm install html-to-jsx` or add it to package.json.
TypeError: htmlToJsx is not a function
Incorrect import of the module (e.g., using named import when default export is expected).
fix
Use default import: `import htmlToJsx from 'html-to-jsx'` or CommonJS: `const htmlToJsx = require('html-to-jsx').htmlToJsx`.
htmlToJsx(...) is not a function
Import returned an object with a method named htmlToJsx instead of a function.
fix
Use `const { htmlToJsx } = require('html-to-jsx')` in CommonJS or `import { htmlToJsx } from 'html-to-jsx'` (if supported).
Upgrade
Version history
0.0.4latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
6 hits · last 30 days
node
6
Resources
html-to-jsx — npm install html-to-jsx · libregistry