Registry / serialization / unist-builder

unist-builder

JSON →
library4.0.0jsnpmunverified

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.

npm install unist-builder
INSTALL
IMPORT
SIG · UNIST-BUILDER
U
unist-builder
serializationjavascriptv4.0.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

u
import { u } from 'unist-builder'
const u = require('unist-builder')
The package is ESM-only since v3.0.0. CommonJS `require` is not supported for v3+.
ChildrenOrValue
import type { ChildrenOrValue } from 'unist-builder'
import { ChildrenOrValue } from 'unist-builder'
This is a TypeScript type export; use `import type` for clarity and better tooling support.
Props
import type { Props } from 'unist-builder'
import { Props } from 'unist-builder'
This is a TypeScript type export; use `import type` for clarity and better tooling support.

Demonstrates creating a nested unist tree structure using the `u` function with various node types, properties, children, and values.

import {u} from 'unist-builder' const tree = u('root', [ u('subtree', {id: 1}), u('subtree', {id: 2}, [ u('node', [u('leaf', 'leaf 1'), u('leaf', 'leaf 2')]), u('leaf', {id: 3}, 'leaf 3'), u('void', {id: 4}) ]) ]) console.dir(tree, {depth: undefined})
Debug
Known issues
breakingVersion 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.
fix
Upgrade your Node.js environment to version 16 or higher.
affects: >=4.0.0
breakingAs 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.
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.
affects: >=3.0.0
breakingVersion 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.
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.
affects: >=2.0.0, >=4.0.0
breakingVersion 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.
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`.
affects: >=4.0.0
gotchaVersion 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.
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).
affects: >=2.0.1
Errors
Common errors & fixes
SyntaxError: Cannot use import statement outside a module
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.
fix
Ensure your `package.json` contains `"type": "module"` or use dynamic `import('unist-builder').then(...)` if you must remain in a CommonJS context.
TypeError: u is not a function
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.
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')`.
ReferenceError: require is not defined
Using `require()` in an ES module file or environment, particularly with `unist-builder` versions 3.0.0 and later, which are ESM-only.
fix
Switch to `import` statements (e.g., `import { u } from 'unist-builder'`) as the package is ESM-only since v3.0.0.
ERR_PACKAGE_PATH_NOT_EXPORTED
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.
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.
Upgrade
Version history
4.0.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
7 hits · last 30 days
node
6
OpenAI (training)
1
Resources
unist-builder — npm install unist-builder · libregistry