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
muslnode 18–226 runs
build_error
glibcnode 18–226 runs
build_error
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
babelParse
✓ import { babelParse } from 'ast-kit'
✗ const { babelParse } = require('ast-kit')
Package is ESM-only since v2.0.0; require() will fail.
babelParseFile
✓ import { babelParseFile } from 'ast-kit'
✗ import babelParseFile from 'ast-kit'
Named export, not default.
walkAST
✓ import { walkAST } from 'ast-kit'
✗ import { walk } from 'ast-kit'
Function is named walkAST, not walk.
Demonstrates parsing, file reading, AST walking, identifier extraction, and code generation.
import { babelParse, babelParseFile, walkAST, walkIdentifiers, generate } from 'ast-kit'
// Parse a code string
const ast = babelParse('const x = 1 + 2', { sourceType: 'module' })
console.log(ast.program.body[0].type) // 'VariableDeclaration'
// Parse a file
const fileAst = await babelParseFile('./example.js')
// Walk the AST
walkAST(ast, {
enter(node) {
console.log('Entering:', node.type)
},
leave(node) {
console.log('Leaving:', node.type)
}
})
// Walk only identifiers
walkIdentifiers(ast, (id) => {
console.log('Found identifier:', id.name)
})
// Generate code from AST (requires @babel/generator)
import generateCode from '@babel/generator'
const output = generateCode(ast).code
console.log(output) // 'const x = 1 + 2;'
Errors
Common errors & fixes
Error [ERR_REQUIRE_ESM]: require() of ES Module /path/to/ast-kit/index.mjs not supported.
Package is ESM-only since v2.0.0; calling require() is invalid.
fixUse import { ... } from 'ast-kit' or dynamic import() instead of require(). TypeError: babelParse is not a function
Using default import (import babelParse from 'ast-kit') instead of named import.
fixUse import { babelParse } from 'ast-kit'. SyntaxError: Unexpected token 'export'
Using CommonJS (require) with ESM-only package without transpilation.
fixSet { type: 'module' } in package.json and use import syntax, or upgrade Node to >=20.19.0. Audit
Dependencies
@babel/typesrequiredUsed for AST node types and manipulation; deep dependency of ast-kit.
@babel/parserrequiredUsed in babelParse and babelParseFile for parsing code into AST.