unist-util-visit is a fundamental utility for traversing unist (Universal Syntax Tree) compliant abstract syntax trees, which are commonly used in remark, retext, and rehype for processing Markdown, natural language, and HTML. It allows developers to walk a tree and apply a `visitor` function to each node (or specific nodes matching a test) encountered during traversal. The current stable version is 5.1.0, last published 3 months ago (as of January 2026), and the project exhibits an active release cadence with frequent patch/minor updates and occasional major versions that introduce breaking changes, often related to Node.js environment requirements or ESM adoption. A key differentiator is its focus on simple node visiting, contrasting with `unist-util-visit-parents` which provides access to the full parent stack during traversal. This package is ESM-only and requires Node.js 16 or newer.
npm install unist-util-visitVerified import paths — ran on the pinned version, not inferred.
Demonstrates parsing Markdown into a unist tree, then using `visit` to traverse specific node types. It shows how to access node value, index, and parent, and how to use `SKIP` and `EXIT` to control traversal flow.
Migrate your project to use ES modules (`import`/`export`) or use an older version of the library (`unist-util-visit@^2`). Ensure your `package.json` specifies `"type": "module"` or use `.mjs` file extensions.
Upgrade your Node.js environment to version 16 or higher. The `unified` collective maintains compatibility with maintained Node.js versions.
Always import directly from `unist-util-visit`. Avoid using private or deep import paths that are not explicitly exported.
Update your `visitor` functions to handle `undefined` checks where `null` was previously expected.
Review your TypeScript code involving `visit` calls, especially the `visitor` function's parameters. You may need to update type definitions or use type guards to properly narrow types.
Be mindful when replacing nodes while attempting to skip children. If this behavior is problematic, consider returning `EXIT` or restructuring your traversal logic.
Change `const visit = require('unist-util-visit')` to `import { visit } from 'unist-util-visit'` and ensure your project uses ES modules (e.g., `"type": "module"` in `package.json`).Ensure you use named imports: `import { visit } from 'unist-util-visit'`.Update your `package.json` with `"type": "module"`, use `.mjs` file extensions for ESM files, or upgrade Node.js to version 16+.
Update your TypeScript types and logic to explicitly handle `undefined` instead of `null` for these parameters in your `visitor` functions.
No dependency data recorded yet.