{"id":10758,"library":"dom-walk","title":"DOM Walk","description":"dom-walk is a minimalistic, client-side utility library designed for iteratively traversing a DOM node and its children. Currently at version 0.1.2, it was last published approximately six years ago (as of early 2020), indicating it is no longer actively maintained. Despite its age and low version number, it reports a surprisingly high weekly download count, suggesting it is a transitive dependency in many projects or widely used in legacy applications. The library provides a single `walk` function that takes a list of nodes and a callback to execute for each node. Its simplicity and small footprint were advantageous in older web development contexts, but its lack of ongoing development and reliance on CommonJS make it less suitable for modern projects that prioritize ESM, TypeScript, and active community support. Alternatives or native DOM traversal methods are generally preferred for new development.","status":"abandoned","version":"0.1.2","language":"javascript","source_language":"en","source_url":"git://github.com/Raynos/dom-walk","tags":["javascript"],"install":[{"cmd":"npm install dom-walk","lang":"bash","label":"npm"},{"cmd":"yarn add dom-walk","lang":"bash","label":"yarn"},{"cmd":"pnpm add dom-walk","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"This package is CommonJS only. While `import walk from 'dom-walk'` might work with bundlers, the original intent was `require`.","wrong":"const walk = require('dom-walk')","symbol":"walk","correct":"import walk from 'dom-walk'"},{"note":"This is the original and intended CommonJS usage as shown in the package's documentation.","symbol":"walk","correct":"const walk = require('dom-walk')"}],"quickstart":{"code":"import walk from 'dom-walk';\n\n// Ensure this code runs in a browser environment with a DOM.\n// For Node.js, you would need a JSDOM-like environment.\n\nfunction setupAndWalkDOM() {\n  // Create some dummy DOM structure for the example\n  document.body.innerHTML = `\n    <div id=\"root\">\n      <p>Paragraph 1</p>\n      <div>\n        <span>Span 1</span>\n        <p>Paragraph 2</p>\n      </div>\n    </div>\n  `;\n\n  const nodesToWalk = document.body.childNodes;\n\n  console.log('Starting DOM walk...');\n  walk(nodesToWalk, function (node) {\n    if (node.nodeType === Node.ELEMENT_NODE) {\n      console.log(\"Visited element node:\", node.tagName.toLowerCase(), 'id:', node.id);\n    } else if (node.nodeType === Node.TEXT_NODE && node.textContent.trim().length > 0) {\n      console.log(\"Visited text node:\", node.textContent.trim());\n    }\n  });\n  console.log('DOM walk complete.');\n}\n\n// Execute the setup and walk once the DOM is ready\nif (document.readyState === 'loading') {\n  document.addEventListener('DOMContentLoaded', setupAndWalkDOM);\n} else {\n  setupAndWalkDOM();\n}","lang":"javascript","description":"Demonstrates how to import and use the `walk` function to traverse DOM nodes, logging the type and content of each visited node."},"warnings":[{"fix":"Use `const walk = require('dom-walk');` in CommonJS modules. For ESM, consider native DOM traversal methods or modern alternatives, or ensure your bundler (e.g., Webpack, Rollup) is configured to handle CJS imports.","message":"The package is CommonJS-only (`require`) and does not officially support ES Modules (`import`). Direct `import` statements may require bundler configuration or result in errors in pure ESM environments.","severity":"breaking","affected_versions":">=0.1.0"},{"fix":"Avoid using in new projects. For existing projects, consider migrating to native DOM traversal (`Node.childNodes`, `Node.children`, `TreeWalker`) or a actively maintained modern DOM utility library to ensure compatibility and security.","message":"This package is unmaintained, with its last publish dating back approximately six years. It has not seen updates for new browser APIs, bug fixes, or security patches.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Create a `dom-walk.d.ts` file with `declare module 'dom-walk';` or define basic types for the `walk` function manually: `declare module 'dom-walk' { function walk(nodes: NodeListOf<ChildNode> | Node[], callback: (node: Node) => void): void; export = walk; }`.","message":"The package does not provide official TypeScript type definitions. Usage in TypeScript projects will require manual declaration files (`.d.ts`) or reliance on `@ts-ignore`.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Ensure the code is executed in a browser context. For server-side rendering or Node.js testing, use JSDOM or a similar library to simulate a DOM environment if `dom-walk` is a necessary dependency.","message":"This library is designed exclusively for browser DOM traversal and will not function in a Node.js environment without a DOM implementation like JSDOM.","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":"If using a bundler, it might handle `import walk from 'dom-walk';`. Otherwise, in pure ESM, you cannot `require`. Consider using native DOM traversal or a modern, ESM-compatible library.","cause":"Attempting to use `require('dom-walk')` directly within an ES Module (`.mjs` file or `\"type\": \"module\"` package).","error":"ReferenceError: require is not defined in ES module scope"},{"fix":"Ensure the code runs in a browser. If you must run in Node.js, integrate JSDOM: `const { JSDOM } = require('jsdom'); const dom = new JSDOM('<!DOCTYPE html><body></body>'); global.document = dom.window.document;` before importing and using `dom-walk`.","cause":"Attempting to run `dom-walk` in a Node.js environment without a simulated DOM (`document` object is undefined).","error":"TypeError: Cannot read properties of undefined (reading 'childNodes')"}],"ecosystem":"npm"}