{"id":14571,"library":"fast-html-parser","title":"Fast HTML Parser","description":"Fast HTML Parser (version 1.0.1) is an HTML parsing library designed for high performance and low-cost processing of large HTML files, generating a simplified DOM tree with basic element query support. It prioritizes speed, often outperforming alternatives like older versions of `htmlparser2` in its benchmarks. Key differentiators include its focus on raw parsing speed and a simplified DOM structure. However, this package is effectively abandoned, with its last release over a decade ago. It lacks active maintenance, modern features, and critical security updates. For current projects requiring a fast HTML parser, `node-html-parser` (a separate, actively maintained package that appears to be a spiritual successor or re-implementation) is the recommended alternative, offering similar performance goals with ongoing development and broader feature support.","status":"abandoned","version":"1.0.1","language":"javascript","source_language":"en","source_url":"https://github.com/ashi009/node-fast-html-parser","tags":["javascript"],"install":[{"cmd":"npm install fast-html-parser","lang":"bash","label":"npm"},{"cmd":"yarn add fast-html-parser","lang":"bash","label":"yarn"},{"cmd":"pnpm add fast-html-parser","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"This package is CommonJS-only; direct ES module imports are not supported.","wrong":"import HTMLParser from 'fast-html-parser';","symbol":"HTMLParser","correct":"const HTMLParser = require('fast-html-parser');"},{"note":"The `parse` function is a method on the `HTMLParser` object, not a top-level named export for CommonJS modules, and ESM imports are not supported by this version.","wrong":"import { parse } from 'fast-html-parser';","symbol":"parse","correct":"const { parse } = require('fast-html-parser'); // Destructures the 'parse' method from the main export"},{"note":"HTMLElement is an internal class representing parsed DOM elements; it is not exposed for direct import.","symbol":"HTMLElement","correct":"// HTMLElement instances are returned by parse and query methods, not directly imported."}],"quickstart":{"code":"const HTMLParser = require('fast-html-parser');\n\nconst htmlContent = `\n  <div id=\"container\">\n    <h1>Welcome</h1>\n    <p class=\"intro\">Hello, <span class=\"name\">World</span>!</p>\n    <ul>\n      <li>Item 1</li>\n      <li>Item 2</li>\n    </ul>\n  </div>`;\n\nconst root = HTMLParser.parse(htmlContent);\n\nconsole.log('Root structure:\\n', root.firstChild.structure);\n\nconst container = root.querySelector('#container');\nif (container) {\n  const welcomeHeading = container.querySelector('h1');\n  console.log('\\nWelcome Heading Text:', welcomeHeading ? welcomeHeading.text : 'Not found');\n\n  const introParagraph = container.querySelector('.intro');\n  console.log('Intro Paragraph HTML:', introParagraph ? introParagraph.rawText : 'Not found');\n\n  const spanName = introParagraph ? introParagraph.querySelector('.name') : null;\n  console.log('Span Name Text:', spanName ? spanName.text : 'Not found');\n}","lang":"javascript","description":"Demonstrates parsing HTML, accessing the root element, querying elements by ID and class, and extracting text and raw HTML content."},"warnings":[{"fix":"Migrate to an actively maintained alternative like `node-html-parser` for ongoing support and security updates.","message":"The `fast-html-parser` package (v1.0.1) is abandoned and has not been updated in over a decade. It is not recommended for new projects due to potential unpatched bugs, security vulnerabilities, and lack of modern feature support.","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"Manually traverse the DOM tree for more complex selection criteria or use a different parser with full CSS selector support.","message":"CSS selector support is limited to `tagName`, `#id`, and `.class` selectors only. Advanced CSS selectors (e.g., attribute selectors, pseudo-classes, direct child combinators) are not supported, which differs significantly from browser-native `querySelector` implementations.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Be aware of this non-standard behavior. If you need all matches, you might need to implement a recursive search or use a different library.","message":"The `HTMLElement#querySelectorAll()` method does not behave like standard browser `querySelectorAll()`. It stops searching a sub-tree after finding the *first* match within that sub-tree, potentially returning an incomplete list of matches.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Only enable these options if absolutely necessary for your parsing logic and be aware of the performance trade-offs.","message":"The `lowerCaseTagName`, `script`, `style`, and `pre` parsing options are noted to 'hurt performance heavily/slightly'. Enabling these options will negate some of the library's primary performance benefits.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Ensure HTML input is as well-formed as possible, or use a more forgiving, spec-compliant parser if robust error handling for malformed HTML is critical.","message":"This parser is designed for speed and may not correctly parse all malformed HTML. While it handles common errors like missing closing `<li>` or `<td>` tags, highly irregular or broken HTML might lead to incorrect DOM structures.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Use CommonJS `require` syntax: `const HTMLParser = require('fast-html-parser'); const root = HTMLParser.parse(...)`.","cause":"Attempting to use a named import (e.g., `import { parse } from 'fast-html-parser';`) in an ESM context when the package is CommonJS-only and exports the `parse` function as a method of its default export.","error":"TypeError: HTMLParser.parse is not a function"},{"fix":"This package is CommonJS-only. For modern ESM environments, consider using `node-html-parser` which offers ESM support, or dynamically import this package using `import('fast-html-parser').then(mod => mod.parse(...))` (though not officially supported/tested for this old package).","cause":"Trying to use CommonJS `require()` in an ES module (ESM) environment (e.g., a file with `\"type\": \"module\"` in `package.json` or `.mjs` extension) without proper CommonJS interoperability.","error":"ReferenceError: require is not defined"}],"ecosystem":"npm"}