{"id":13129,"library":"es-html-parser","title":"ES HTML Parser","description":"es-html-parser is a JavaScript/TypeScript library designed for parsing HTML content into an Abstract Syntax Tree (AST) that closely adheres to the ESTree specification. It also provides access to the raw token stream generated during parsing. Currently at version 0.3.1, this project originated as a fork of `hyntax` and is actively developed to align its AST output with ESTree standards, making it suitable for tooling that processes HTML with familiar JavaScript AST traversal patterns. While the release cadence is not explicitly defined, its 0.x version implies ongoing development and potential for breaking changes between minor versions. It differentiates itself by its ESTree-like AST structure, which can be advantageous for developers already familiar with JavaScript AST manipulation.","status":"active","version":"0.3.1","language":"javascript","source_language":"en","source_url":null,"tags":["javascript","typescript"],"install":[{"cmd":"npm install es-html-parser","lang":"bash","label":"npm"},{"cmd":"yarn add es-html-parser","lang":"bash","label":"yarn"},{"cmd":"pnpm add es-html-parser","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"The library primarily uses named exports and is designed for ESM. CommonJS 'require' syntax will not work by default.","wrong":"const { parse } = require('es-html-parser');","symbol":"parse","correct":"import { parse } from 'es-html-parser';"},{"note":"When importing only types, use 'import type' for better tree-shaking and to prevent runtime issues in environments that don't strip type imports.","wrong":"import { ParseResult } from 'es-html-parser';","symbol":"ParseResult","correct":"import type { ParseResult } from 'es-html-parser';"},{"note":"Constants like TokenTypes are directly exported from the main package entry point, not from a subpath.","wrong":"import * as TokenTypes from 'es-html-parser/TokenTypes';","symbol":"TokenTypes","correct":"import { TokenTypes } from 'es-html-parser';"}],"quickstart":{"code":"import { parse } from 'es-html-parser';\n\nconst htmlInput = `\n  <!DOCTYPE html>\n  <html>\n    <head>\n      <title>Hello Parser</title>\n    </head>\n    <body>\n      <button type=\"button\">Click me</button>\n      <script>\n        console.log('Parser demo');\n      </script>\n    </body>\n  </html>\n`;\n\nconst { ast, tokens } = parse(htmlInput, {\n  rawContentTags: ['script', 'style'] // Treat script/style content as raw text\n});\n\nconsole.log('Parsed AST (root node):', JSON.stringify(ast, null, 2));\nconsole.log('Generated Tokens (first 5):', tokens.slice(0, 5));\n// Further processing of AST or tokens can be done here","lang":"typescript","description":"This quickstart demonstrates parsing a basic HTML string, including script tags, and accessing the resulting AST and tokens. It explicitly uses the `rawContentTags` option for common embedded content."},"warnings":[{"fix":"Always pin to exact versions (e.g., `\"es-html-parser\": \"0.3.1\"`) and review release notes carefully when upgrading to newer `0.x` versions.","message":"The package is currently in a pre-1.0.0 state (version 0.3.1). This means the API might not be stable, and breaking changes can occur in minor or even patch releases without strictly adhering to semantic versioning.","severity":"gotcha","affected_versions":"<1.0.0"},{"fix":"Always provide an array of tag names to `rawContentTags` in the options if their content should be treated as raw text (e.g., `{ rawContentTags: ['script', 'style', 'custom-raw-tag'] }`).","message":"The `rawContentTags` option is crucial for correct parsing of tags like `<script>` or `<style>`, or custom elements whose inner content should not be parsed as HTML. Forgetting to specify them can lead to incorrect AST generation for their children.","severity":"gotcha","affected_versions":">=0.1.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Ensure your project is configured for ESM by adding `\"type\": \"module\"` to your `package.json` or by using a bundler (like Webpack, Rollup, Parcel, or esbuild) that transpiles ESM to CJS if targeting older environments.","cause":"Attempting to use `import` syntax in a CommonJS (CJS) environment (e.g., a Node.js script without `\"type\": \"module\"` in package.json, or an older Node.js version).","error":"SyntaxError: Cannot use import statement outside a module"},{"fix":"Verify that `import { parse } from 'es-html-parser';` is correctly used and that your bundler configuration is compatible with ESM modules. Ensure the package is installed correctly and not corrupted.","cause":"This error typically occurs in bundled environments when a named export (`parse`) is incorrectly treated as a default export or when destructuring fails due to a module resolution issue.","error":"TypeError: (0 , es_html_parser__WEBPACK_IMPORTED_MODULE_0__.parse) is not a function"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":""}