Registry / devops / babel-traverse

babel-traverse

JSON →
library6.26.0jsnpmunverified

babel-traverse (v6.26.0) is the deprecated Babel 6 package for traversing and manipulating ASTs. It was the core traversal engine behind Babel 6, maintaining tree state and allowing node replacement, removal, and insertion. Key differentiator: provides a visitor pattern for AST mutation via Path objects. Since Babel 7, this package has been replaced by @babel/traverse. v6.26.0 is the final release of the standalone package; it depends on babel-types and babel-generator. It does not ship TypeScript definitions, and is CommonJS-only. The v8.0.0-rc.3 release exists but the babel-traverse name is no longer published under the @babel scope.

npm install babel-traverse
INSTALL
IMPORT
SIG · BABEL-TRAVERSE
B
babel-traverse
devopsjavascriptv6.26.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.

default export (traverse)
import traverse from 'babel-traverse';
const traverse = require('babel-traverse').default;
The default export is a function; CommonJS require yields the function directly, no .default needed.
main traverse function (CommonJS)
const traverse = require('babel-traverse');
import { traverse } from 'babel-traverse';
Named export 'traverse' does not exist; the module exports a single default function.
no named exports
The module only has a default export; no named exports like 'Visitor' or 'Path' are publicly exported.
import { Visitor } from 'babel-traverse';
Types must be obtained from @babel/traverse or defined locally.

Parses code with babylon, traverses AST using babel-traverse to rename identifier 'n' to 'x', then generates output with babel-generator.

import * as babylon from 'babylon'; import traverse from 'babel-traverse'; import generate from 'babel-generator'; const code = `function square(n) { return n * n; }`; const ast = babylon.parse(code); traverse(ast, { enter(path) { if (path.isIdentifier({ name: 'n' })) { path.node.name = 'x'; } } }); const output = generate(ast, {}, code); console.log(output.code); // 'function square(x) { return x * x; }'
Debug
Known issues
deprecatedbabel-traverse is deprecated in favor of @babel/traverse (Babel 7+). This package is no longer maintained.
fix
Migrate to @babel/traverse: npm install @babel/traverse and update imports to import traverse from '@babel/traverse'.
affects: 6.x
breakingBabel 8 (v8.0.0-rc.x) introduces strictNullChecks for traverse, which may break code that relied on nullable path properties being unchecked.
fix
Upgrade to @babel/traverse and add null checks for path properties (e.g., path.parent, path.container) as they may be null.
affects: >=8.0.0-rc.0
gotchaThe package does not ship TypeScript declarations; using with TypeScript requires custom type stubs or migration to @babel/traverse.
fix
Either write a .d.ts file (e.g., declare module 'babel-traverse' { const traverse: any; export default traverse; }) or switch to @babel/traverse.
affects: 6.x
gotchababel-traverse v6 is CommonJS-only and cannot be imported as a named export; default import or require is required.
fix
Use `import traverse from 'babel-traverse'` (with esModuleInterop) or `const traverse = require('babel-traverse')`.
affects: 6.x
gotchaNo support for async/await or promise-based traversal; all visitor callbacks are synchronous.
fix
Consider using @babel/traverse which supports async visitors via `traverse(ast, { enter: async function(path) { ... } })`.
affects: 6.x
Errors
Common errors & fixes
TypeError: traverse is not a function
Using named import like `import { traverse } from 'babel-traverse'` when the package has only a default export.
fix
Use `import traverse from 'babel-traverse'` or `const traverse = require('babel-traverse')`.
Cannot find module 'babel-traverse'
The package is not installed, or you are using a bundler that cannot resolve the name (e.g., Webpack with strict module resolution).
fix
Run `npm install babel-traverse@6.26.0` or switch to `@babel/traverse` for Babel 7+ compatibility.
Error: Cannot find module 'babel-types' from 'babel-traverse'
babel-traverse has a peer dependency on babel-types which is not installed.
fix
Run `npm install babel-types@6.26.0`.
TypeError: path.isIdentifier is not a function
Using a malformed visitor object or the path object is not a valid NodePath. Common when overriding enter without function.
fix
Ensure visitor callbacks are functions: `traverse(ast, { enter(path) { ... } })`.
Upgrade
Version history
6.26.0latest on npm
Audit
Dependencies
babel-typesrequiredRequired for AST node type checking and construction; used internally by traverse.
babel-generatoroptionalMay be needed for code generation from traversed AST.
babylonoptionalCommonly used together for parsing code before traversal.
Agent activity
14 hits · last 30 days
node
12
Resources