hast-util-from-parse5 is a specialized utility within the unified.js ecosystem designed to transform an AST (Abstract Syntax Tree) generated by the `parse5` HTML parser into a HAST (Hypertext Abstract Syntax Tree). This package is crucial for developers who parse HTML using `parse5` and then wish to process the resulting tree using the vast array of HAST-compatible tools and plugins. The current stable version is 8.0.3, with releases typically focusing on dependency updates, minor bug fixes, and periodic major versions to align with Node.js LTS releases and significant internal changes (e.g., ESM migration in v7, Node.js 16 requirement in v8). Its key differentiator is its role as a bridge between the widely used `parse5` parser and the expressive `hast` AST format, enabling seamless integration into unified processor workflows for tasks like linting, transforming, or compiling HTML content.
npm install hast-util-from-parse5Verified import paths — ran on the pinned version, not inferred.
Demonstrates parsing an HTML file using `parse5`, converting the `parse5` AST to a `hast` AST, and inspecting the resulting `hast` tree.
Upgrade your Node.js environment to version 16 or later. For projects requiring older Node.js, use `hast-util-from-parse5@7`.
Migrate your project to use ESM `import` statements. Ensure your `package.json` has `"type": "module"` or use `.mjs` file extensions for modules importing this package.
Update calls to `fromParse5` from `fromParse5(tree, file)` to `fromParse5(tree, {file: file})`.Run `npm update` or manually update relevant `@types/*` packages, especially `@types/hast`, in your project.
Always use named imports: `import { fromParse5 } from 'hast-util-from-parse5'`.Ensure your input `parse5` AST represents HTML documents. If non-HTML doctypes were previously handled, consider pre-processing or using a different utility.
Change `const fromParse5 = require('hast-util-from-parse5')` to `import { fromParse5 } from 'hast-util-from-parse5'` in your module, and ensure your project is configured for ESM (e.g., `"type": "module"` in `package.json`).Update your call from `fromParse5(ast, myFile)` to `fromParse5(ast, { file: myFile })`.Verify that you are using a named import: `import { fromParse5 } from 'hast-util-from-parse5'`. Ensure your build configuration correctly handles ESM imports.Confirm your Node.js version is 16+ and your package version is 7.0.0 or higher. Ensure you are using `import { fromParse5 } from 'hast-util-from-parse5'` and not a default import. Re-installing `node_modules` might also help resolve corrupt caches.