jscodeshift is a powerful toolkit for automating code transformations (codemods) across JavaScript and TypeScript projects. It operates by parsing source code into an Abstract Syntax Tree (AST), allowing programmatic manipulation, and then printing the modified AST back into code. The current stable version is 17.3.0, released in early 2026. While lacking a fixed release cadence, the project is actively maintained, with frequent minor and patch updates primarily driven by `recast` dependency bumps to support new language features (e.g., recent TypeScript syntax) and address parsing quirks. A significant version jump from `v0.x` to `v17.0.0` occurred in August 2024, signaling its maturity rather than a traditional `1.0` release. Its core strength lies in its tight integration with `recast`, which excels at preserving original code formatting, comments, and whitespace, minimizing disruption to a codebase's aesthetics during large-scale refactors. It offers a robust CLI runner for applying transforms to files and an intuitive API for writing complex, style-preserving codemods.
npm install jscodeshiftVerified import paths — ran on the pinned version, not inferred.
This TypeScript quickstart demonstrates a basic codemod that updates `var` declarations to `let` or `const` based on a simplistic immutability check, then shows how to execute it via the `jscodeshift` CLI.
Upgrade your Node.js environment to version 16 or newer. Use `nvm install 16 && nvm use 16` or similar version management tools.
Review the changelog for any specific breaking changes (e.g., Node.js version requirement) beyond the version number itself when upgrading from pre-v17 versions.
Immediately upgrade `jscodeshift` to version `0.13.1` or higher, which replaced `colors` with `chalk`, mitigating the vulnerability.
Always specify the appropriate parser using the `--parser` CLI option (e.g., `--parser=ts` for TypeScript, `--parser=tsx` for TSX/JSX, `--parser=flow` for Flow). For custom Babel/Flow configurations, use `--parser-config` pointing to a JSON file.
If a strict code style or reformatting is required after running a codemod, consider integrating a separate formatting step (e.g., Prettier or ESLint with `--fix`) into your workflow after the codemod execution.
Specify the correct parser via the CLI, for example: `jscodeshift -t transform.js my-file.ts --parser=ts` or `--parser=tsx` for JSX/TSX. Use `--parser-config` for custom Babel/Flow configurations.
Ensure your `export default function transformer(...)` always returns `root.toSource()` after modifications, or `null` if the file should not be changed.
Verify the exact import path. Ensure `jscodeshift` is installed and the subpath `jscodeshift/testUtils` is correctly resolved by your module resolver. This typically occurs in test files.
Access the jscodeshift API through the `api` object provided to your transform function: `export default function transformer(fileInfo, api) { const j = api.j; /* ... */ }`.