{"id":12292,"library":"unist-util-inspect","title":"Unist Tree Inspector","description":"unist-util-inspect is a utility for pretty-printing Abstract Syntax Trees (ASTs) that conform to the unist specification. It provides a human-readable, terser output format specifically tailored for unist nodes, making it easier to debug and understand tree structures compared to verbose JSON representations. The current stable version is 8.1.0, actively maintained with incremental updates. Major releases tend to align with Node.js LTS versions, requiring Node.js 16+ since version 8.0.0 and having transitioned to ESM-only in version 7.0.0. The library aims for a focused utility approach within the broader unified ecosystem, prioritizing clear and concise tree visualization and offering a custom format instead of generic object serialization.","status":"active","version":"8.1.0","language":"javascript","source_language":"en","source_url":"https://github.com/syntax-tree/unist-util-inspect","tags":["javascript","unist","unist-util","util","utility","inspect","debug","log","console","typescript"],"install":[{"cmd":"npm install unist-util-inspect","lang":"bash","label":"npm"},{"cmd":"yarn add unist-util-inspect","lang":"bash","label":"yarn"},{"cmd":"pnpm add unist-util-inspect","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"The package is ESM-only since v7.0.0. CommonJS `require()` is not supported.","wrong":"const inspect = require('unist-util-inspect')","symbol":"inspect","correct":"import { inspect } from 'unist-util-inspect'"},{"note":"This function is deprecated since v8.1.0. Use `inspect(tree, { color: true })` instead.","symbol":"inspectColor","correct":"import { inspectColor } from 'unist-util-inspect'"},{"note":"Type-only import for configuring inspection options. Available since v5.0.0.","symbol":"Options","correct":"import type { Options } from 'unist-util-inspect'"}],"quickstart":{"code":"import { u } from 'unist-builder';\nimport { inspect } from 'unist-util-inspect';\n\nconst complexTree = u('root', [\n  u('paragraph', [\n    u('text', 'Hello, world!'),\n    u('emphasis', [u('text', 'This is emphasized.')])\n  ]),\n  u('list', { ordered: true }, [\n    u('listItem', [u('text', 'First item')]),\n    u('listItem', [u('strong', [u('text', 'Second item with strong text')])])\n  ]),\n  u('code', { lang: 'js' }, 'console.log(\"Code example\");')\n]);\n\nconsole.log('--- Uncolored Inspection ---');\nconsole.log(inspect(complexTree, { color: false, showPositions: true }));\n\nconsole.log('\\n--- Colored Inspection (default) ---');\nconsole.log(inspect(complexTree));\n\n// Demonstrates basic usage and optional parameters for output control.","lang":"typescript","description":"Demonstrates how to import and use the `inspect` function with a sample unist tree, showing both colored and uncolored output options."},"warnings":[{"fix":"Upgrade your Node.js environment to version 16 or a newer maintained release.","message":"Version 8.0.0 and newer require Node.js 16 or later. Running on older Node.js versions will result in an error.","severity":"breaking","affected_versions":">=8.0.0"},{"fix":"Ensure you are using `import` statements for all package imports. If your project is CommonJS, you may need to convert it to ESM or use a dynamic import `import('unist-util-inspect')`.","message":"The package transitioned to ESM-only with an `export` map in v8.0.0, building upon its initial ESM migration in v7.0.0. Direct CommonJS `require()` statements will fail.","severity":"breaking","affected_versions":">=7.0.0"},{"fix":"Replace `inspectColor(tree)` with `inspect(tree, { color: true })` and `inspectNoColor(tree)` with `inspect(tree, { color: false })`.","message":"The `inspectColor` and `inspectNoColor` functions are deprecated. They will be removed in a future major version.","severity":"deprecated","affected_versions":">=8.1.0"},{"fix":"Review type declarations and ensure compatibility with your project's TypeScript configuration. Use `import type` for type-only imports where appropriate.","message":"Version 5.0.0 introduced TypeScript types. While beneficial, this could cause breaking changes for existing TypeScript projects if type definitions conflict or are not handled correctly.","severity":"breaking","affected_versions":">=5.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 { inspect } from 'unist-util-inspect'` and ensure your project is configured for ESM, or use dynamic import `import('unist-util-inspect')`.","cause":"Attempting to use `require('unist-util-inspect')` in a CommonJS module after the package became ESM-only.","error":"ERR_REQUIRE_ESM"},{"fix":"Update your Node.js environment to version 16 or newer. You can use `nvm` to manage Node.js versions easily.","cause":"Running `unist-util-inspect` on a Node.js version older than 16.","error":"Error: This module requires Node.js 16 or later."},{"fix":"Migrate to using the `color` option with the main `inspect` function: `inspect(tree, { color: true })` for colored output and `inspect(tree, { color: false })` for uncolored output.","cause":"Using the deprecated `inspectColor` or `inspectNoColor` functions in a TypeScript project, potentially after they have been removed or type definitions have been updated.","error":"Property 'inspectColor' does not exist on type 'typeof import(\"unist-util-inspect\")'."}],"ecosystem":"npm"}