{"id":12287,"library":"unist-util-find-after","title":"Unist Utility: Find Node After","description":"This package, `unist-util-find-after`, provides a lightweight utility for navigating unist (Universal Syntax Tree) trees by locating a node immediately following a specified node or index within a parent. Currently at stable version 5.0.0, it adheres to semantic versioning with major releases introducing breaking changes, and maintains active development within the unified collective. A key differentiator is its seamless integration with other `unist` and `unified` ecosystem tools, simplifying tree manipulation tasks that could otherwise be implemented manually. It is explicitly an ESM-only package, requiring Node.js 16 or newer, and ships with full TypeScript type definitions to ensure robust development.","status":"active","version":"5.0.0","language":"javascript","source_language":"en","source_url":"https://github.com/syntax-tree/unist-util-find-after","tags":["javascript","unist","unist-util","util","utility","node","find","after","typescript"],"install":[{"cmd":"npm install unist-util-find-after","lang":"bash","label":"npm"},{"cmd":"yarn add unist-util-find-after","lang":"bash","label":"yarn"},{"cmd":"pnpm add unist-util-find-after","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Used internally for the 'test' function parameter, defining compatibility and behavior for node predicate functions.","package":"unist-util-is","optional":false}],"imports":[{"note":"Package is ESM-only since v4.0.0; CommonJS `require` is not supported.","wrong":"const findAfter = require('unist-util-find-after')","symbol":"findAfter","correct":"import { findAfter } from 'unist-util-find-after'"},{"note":"For Deno or browser environments using esm.sh, ensure to specify the major version in the URL.","symbol":"findAfter","correct":"import { findAfter } from 'https://esm.sh/unist-util-find-after@5'"},{"note":"While `unist-util-find-after` ships types, core Unist types like `Node` are imported from the `unist` package.","symbol":"Node","correct":"import type { Node } from 'unist'"}],"quickstart":{"code":"import { u } from 'unist-builder';\nimport { findAfter } from 'unist-util-find-after';\n\n// Example Unist tree structure\nconst tree = u('tree', [\n  u('leaf', 'leaf 1'),\n  u('parent', [u('leaf', 'leaf 2'), u('leaf', 'leaf 3')]),\n  u('leaf', 'leaf 4'),\n  u('parent', [u('leaf', 'leaf 5')]),\n  u('leaf', 'leaf 6'),\n  u('empty'),\n  u('leaf', 'leaf 7')\n]);\n\n// Find the first 'parent' node after the node at index 1 (which is 'parent' with 'leaf 2', 'leaf 3')\nconsole.log('Finding parent after index 1:', findAfter(tree, 1, 'parent'));\n// Expected output: { type: 'parent', children: [{ type: 'leaf', value: 'leaf 5' }]}\n\n// Find the first 'leaf' node after 'leaf 4' (which is at index 2)\nconst leaf4 = tree.children[2];\nconsole.log('Finding leaf after \"leaf 4\":', findAfter(tree, leaf4, 'leaf'));\n// Expected output: { type: 'leaf', value: 'leaf 6' }\n\n// Find a node after 'leaf 7' (the last child) - should be undefined\nconst leaf7 = tree.children[6];\nconsole.log('Finding node after \"leaf 7\":', findAfter(tree, leaf7));\n// Expected output: undefined","lang":"typescript","description":"Demonstrates how to use `findAfter` to locate a node based on an index or a reference node, with an optional test, within a Unist tree."},"warnings":[{"fix":"Upgrade your Node.js environment to version 16 or newer. For projects that require older Node.js versions, pin `unist-util-find-after` to `<5.0.0`.","message":"Version 5.0.0 changed the minimum Node.js requirement to Node.js 16 or higher. Older Node.js versions are no longer supported.","severity":"breaking","affected_versions":">=5.0.0"},{"fix":"Migrate your codebase to use ECMAScript Modules (ESM) `import` syntax. Ensure your project is configured for ESM (e.g., `\"type\": \"module\"` in `package.json`).","message":"Since version 4.0.0, this package is ESM-only. CommonJS `require()` statements will fail, leading to `ERR_REQUIRE_ESM` errors.","severity":"breaking","affected_versions":">=4.0.0"},{"fix":"Update your code to expect and handle `undefined` as a possible return value from `findAfter` when no node is found.","message":"In version 5.0.0, the `findAfter` function now explicitly yields `undefined` when no matching node is found, instead of `null`. While `null` and `undefined` are often treated similarly, this is a distinct change in return type behavior.","severity":"breaking","affected_versions":">=5.0.0"},{"fix":"Only use the public `findAfter` export directly from the package's root. Avoid relying on internal or private file paths.","message":"Version 5.0.0 changed to use `exports` map. If you were previously relying on direct deep imports to private APIs, those paths are no longer guaranteed and may be broken.","severity":"breaking","affected_versions":">=5.0.0"},{"fix":"Review the `unist-util-is` changelog for `4.0.0` and update your `unist-util-is`-compatible `Test` functions and their types accordingly. Update `@types/unist` as well if necessary.","message":"Version 3.0.0 updated its dependency on `unist-util-is`, which could be a breaking change for TypeScript users if the types for `Test` predicates have changed significantly.","severity":"breaking","affected_versions":">=3.0.0 <4.0.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Change your import statement to `import { findAfter } from 'unist-util-find-after';` and ensure your project is configured for ESM.","cause":"Attempting to use CommonJS `require()` to import `unist-util-find-after` after it transitioned to ESM-only.","error":"ERR_REQUIRE_ESM: require() of ES Module .../node_modules/unist-util-find-after/index.js from .../your-file.js not supported."},{"fix":"Ensure you are using named imports: `import { findAfter } from 'unist-util-find-after';`. Do not attempt `import findAfter from 'unist-util-find-after';` as there is no default export.","cause":"Incorrect ESM import syntax, often when attempting to import a named export as a default, or when transpilng ESM to CJS incorrectly.","error":"TypeError: (0 , unist_util_find_after_1.findAfter) is not a function"},{"fix":"Ensure the first argument passed to `findAfter` is a `Parent` node type that has a `children` property, such as a `Root` or `Parent` node from `unist-builder` or a parsed AST.","cause":"Attempting to access `children` on a non-parent `Node` type. `parent` in `findAfter` must be a `Parent` node (e.g., `Root`, `Element`).","error":"Property 'children' does not exist on type 'Node<Data>'. Did you mean 'options'?"},{"fix":"Upgrade your Node.js environment to version 16 or higher. Alternatively, downgrade `unist-util-find-after` to a version compatible with your Node.js environment (e.g., `npm install unist-util-find-after@^4`).","cause":"Running `unist-util-find-after@5.x` on a Node.js version older than 16, which does not fully support the 'exports' field in `package.json`.","error":"Node.js process exits with code 1 due to unsupported API 'exports' map."}],"ecosystem":"npm"}