{"id":14190,"library":"unist-builder","title":"Unist Tree Builder","description":"unist-builder is a utility package providing a hyperscript-like interface for programmatically constructing unist (Universal Syntax Tree) nodes and trees. It simplifies the creation of Abstract Syntax Trees (ASTs) by replacing repetitive manual object creation with a concise functional API, similar to `createElement` in React or `h` in Vue. The current stable version is 4.0.0, which targets Node.js 16 and later. The package generally follows a deliberate release cadence, with major versions often introducing breaking changes related to Node.js compatibility or module system shifts (e.g., transitioning to ESM). It differentiates itself by offering a fluent API specifically for unist, contrasting with related tools like `hastscript` or `xastscript` which serve HTML and XML ASTs respectively.","status":"active","version":"4.0.0","language":"javascript","source_language":"en","source_url":"https://github.com/syntax-tree/unist-builder","tags":["javascript","unist","unist-util","util","utility","tree","ast","build","builder","typescript"],"install":[{"cmd":"npm install unist-builder","lang":"bash","label":"npm"},{"cmd":"yarn add unist-builder","lang":"bash","label":"yarn"},{"cmd":"pnpm add unist-builder","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"The package is ESM-only since v3.0.0. CommonJS `require` is not supported for v3+.","wrong":"const u = require('unist-builder')","symbol":"u","correct":"import { u } from 'unist-builder'"},{"note":"This is a TypeScript type export; use `import type` for clarity and better tooling support.","wrong":"import { ChildrenOrValue } from 'unist-builder'","symbol":"ChildrenOrValue","correct":"import type { ChildrenOrValue } from 'unist-builder'"},{"note":"This is a TypeScript type export; use `import type` for clarity and better tooling support.","wrong":"import { Props } from 'unist-builder'","symbol":"Props","correct":"import type { Props } from 'unist-builder'"}],"quickstart":{"code":"import {u} from 'unist-builder'\n\nconst tree = u('root', [\n  u('subtree', {id: 1}),\n  u('subtree', {id: 2}, [\n    u('node', [u('leaf', 'leaf 1'), u('leaf', 'leaf 2')]),\n    u('leaf', {id: 3}, 'leaf 3'),\n    u('void', {id: 4})\n  ])\n])\n\nconsole.dir(tree, {depth: undefined})\n","lang":"javascript","description":"Demonstrates creating a nested unist tree structure using the `u` function with various node types, properties, children, and values."},"warnings":[{"fix":"Upgrade your Node.js environment to version 16 or higher.","message":"Version 4.0.0 of `unist-builder` changes its Node.js compatibility, now requiring Node.js 16 or newer. Older Node.js environments are no longer supported.","severity":"breaking","affected_versions":">=4.0.0"},{"fix":"Migrate your project to use ES modules (`import`) for `unist-builder`. For Node.js, ensure your `package.json` includes `\"type\": \"module\"` or use dynamic `import()` within CommonJS files.","message":"As of version 3.0.0, `unist-builder` transitioned to being an ES module (ESM) only. This means CommonJS `require()` statements will fail, and projects must use `import` syntax.","severity":"breaking","affected_versions":">=3.0.0"},{"fix":"Update `@types/unist` to a compatible version (e.g., `npm install @types/unist@latest`) and resolve any type conflicts in your TypeScript project to align with `unist-builder`'s expectations.","message":"Version 2.0.0 introduced TypeScript types, and v4.0.0 further updated `@types/unist`. This can cause compilation errors if existing user-defined types for unist nodes conflict or if an incompatible `@types/unist` version is used.","severity":"breaking","affected_versions":">=2.0.0, >=4.0.0"},{"fix":"Always import symbols directly from `unist-builder` (e.g., `import { u } from 'unist-builder'`). Avoid attempting to import from internal paths like `unist-builder/lib/some-internal-file`.","message":"Version 4.0.0 now uses an `export` map in its `package.json`. This enforces strict module resolution and prevents direct access to internal or private sub-paths of the package.","severity":"breaking","affected_versions":">=4.0.0"},{"fix":"Ensure your JavaScript execution environment supports `Object.assign`. If targeting extremely old browsers, consider a polyfill (though generally not necessary for Node.js usage).","message":"Version 2.0.1 removed the `object-assign` dependency. While unlikely in modern Node.js or browser environments, extremely ancient or unpolyfilled JavaScript environments might lack `Object.assign`, leading to runtime errors.","severity":"gotcha","affected_versions":">=2.0.1"}],"env_vars":null,"search_vec":"'16':65 '4.0.0':61 'abstract':32 'api':46,102 'ast':35,119,129 'break':81 'build':130 'builder':3,6,131 'cadenc':75 'chang':82 'compat':86 'concis':44 'construct':19 'contrast':106 'createel':49 'creation':30,41 'current':57 'deliber':73 'differenti':96 'e.g':91 'esm':94 'fluent':101 'follow':71 'function':45 'general':70 'h':53 'hastscript':111 'html':116 'hyperscript':14 'hyperscript-lik':13 'interfac':16 'introduc':80 'javascript':121 'later':67 'like':15,110 'major':77 'manual':39 'modul':88 'node':24 'node.js':64,85 'object':40 'offer':99 'often':79 'packag':10,69 'programmat':18 'provid':11 'react':51 'relat':83,108 'releas':74 'repetit':38 'replac':37 'respect':120 'serv':115 'shift':90 'similar':47 'simplifi':28 'specif':103 'stabl':58 'syntax':22,33 'system':89 'target':63 'tool':109 'transit':92 'tree':2,23,26,34,128 'typescript':132 'unist':1,5,20,105,122,124 'unist-build':4 'unist-util':123 'univers':21 'util':9,125,126,127 'version':59,78 'vue':55 'xastscript':113 'xml':118","created_at":"2026-04-20T01:58:23.786936+00:00","updated_at":"2026-04-20T01:58:23.786936+00:00","problems":[{"fix":"Ensure your `package.json` contains `\"type\": \"module\"` or use dynamic `import('unist-builder').then(...)` if you must remain in a CommonJS context.","cause":"Attempting to use `import` syntax for `unist-builder` in a Node.js CommonJS environment (e.g., without `\"type\": \"module\"` in `package.json`). `unist-builder` is ESM-only since v3.0.0.","error":"SyntaxError: Cannot use import statement outside a module"},{"fix":"Use the correct ESM named import: `import { u } from 'unist-builder'`. If in a CommonJS file and Node.js v14+, use `const { u } = await import('unist-builder')`.","cause":"This error often occurs when trying to `require('unist-builder')` in Node.js v3.0.0+ (where it's ESM-only) or when incorrectly using a default import (`import u from 'unist-builder'`) when `u` is a named export.","error":"TypeError: u is not a function"},{"fix":"Switch to `import` statements (e.g., `import { u } from 'unist-builder'`) as the package is ESM-only since v3.0.0.","cause":"Using `require()` in an ES module file or environment, particularly with `unist-builder` versions 3.0.0 and later, which are ESM-only.","error":"ReferenceError: require is not defined"},{"fix":"Import only from the main `unist-builder` package directly: `import { u } from 'unist-builder'`. Avoid internal or private paths as they are not guaranteed API.","cause":"Attempting to import from a subpath (e.g., `unist-builder/lib/util`) that is not explicitly exposed via the `exports` field in `package.json`. This behavior was introduced in v4.0.0.","error":"ERR_PACKAGE_PATH_NOT_EXPORTED"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":"","cli_version":null,"type":"library","homepage":null,"github":"https://github.com/syntax-tree/unist-builder","docs":null,"changelog":null,"pypi":null,"npm":"https://www.npmjs.com/package/unist-builder","openapi_spec":null,"status_page":null,"smithery":null,"categories":["serialization"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-17","next_check":"2026-07-18","install_tag":null}}