Registry / devops / babel-codemod

babel-codemod

JSON →
library2.1.2jsnpmunverified

babel-codemod version 2.1.2 (up to 2.1.5) rewrites JavaScript and TypeScript files using Babel plugins, leveraging recast to preserve original formatting with minimal changes. It supports local and remote plugins (e.g., AST Explorer URLs), with optional Prettier output. It includes built-in transpilation via @babel/preset-env and experimental TypeScript support via @babel/preset-typescript. Compared to alternatives like jscodeshift, it uses standard Babel plugins and APIs, reducing the learning curve for Babel users. Active until 2019, now in maintenance mode; requires Node >=6.

npm install babel-codemod
INSTALL
IMPORT
SIG · BABEL-CODEMOD
B
babel-codemod
devopsjavascriptv2.1.2
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.

codemod (CLI)
npx babel-codemod --plugin my-plugin src/
babel-codemod --plugin my-plugin src/ (without npx if not globally installed)
CLI is invoked via `codemod` command or npx. No programmatic API is exposed by default.
babel plugin as codemod
// Use any Babel plugin directly via --plugin flag
Importing babel-codemod as a library in code
babel-codemod is CLI-only; there is no programmatic API. Plugins are standard Babel plugins.

Demonstrates installing babel-codemod and running a Babel plugin on files, including local and remote plugin usage.

# Install globally or use npx npm install -g babel-codemod # Run a Babel plugin on a file codemod --plugin @babel/plugin-transform-arrow-functions src/index.js # Run a remote plugin from AST Explorer (use with caution) codemod --remote-plugin https://astexplorer.net/#/gist/... src/ # Use local plugin with custom babel config codemod --find-babel-config --plugin ./my-plugin.js src/
babel-codemod --version
Debug
Known issues
gotchaRemote plugins execute with full user privileges; only use trusted sources to avoid security risks.
fix
Avoid using --remote-plugin with untrusted URLs.
affects: >=2.0.0
breakingVersion 2.0.0 upgraded to Babel 7; plugins must be compatible with Babel 7 API.
fix
Ensure all plugins are written for Babel 7. Use @babel/plugin-* packages.
affects: >=2.0.0
gotchaTypeScript support is experimental via @babel/preset-typescript; not all valid TypeScript is supported.
fix
Check babel issues for TypeScript support gaps.
affects: >=2.0.0
deprecatedExperimental TypeScript transpilation may be removed in future versions.
fix
Prepare to migrate to official TypeScript compiler if needed.
affects: >=2.0.0
gotchaWhen using --find-babel-config, .babelrc lookup rules apply; missing config may cause unexpected behavior.
fix
Ensure .babelrc is present and all referenced presets/plugins are installed locally.
affects: >=2.0.0
Errors
Common errors & fixes
Error: Cannot find module '@babel/parser'
Missing dependency @babel/parser required since v2.1.1
fix
npm install @babel/parser or upgrade to v2.1.2+ that explicitly depends on it.
Error: Requires Babel 7, but found Babel 6
Using a Babel 6 plugin with babel-codemod v2.x which expects Babel 7 plugins
fix
Use @babel/plugin-* packages for Babel 7, or downgrade to babel-codemod v1.x.
TypeError: Cannot read property 'parse' of undefined
Invalid plugin syntax or plugin not exporting a function
fix
Ensure the plugin exports a function that returns a visitor object.
Error: No babel config found, but --find-babel-config flag used
No .babelrc or babel.config.js found in the project
fix
Create a .babelrc file with the desired plugins/presets, or remove --find-babel-config.
Upgrade
Version history
2.1.2latest on npm
Audit
Dependencies
@babel/corerequiredCore Babel compilation engine
@babel/parserrequiredParses JavaScript/TypeScript into AST
recastrequiredPreserves original formatting when printing transformed code
@babel/preset-envoptionalTranspiles plugin code using latest Babel plugins
@babel/preset-typescriptoptionalExperimental TypeScript support for plugin code
Agent activity
13 hits · last 30 days
node
12
OpenAI (training)
1
Resources
babel-codemod — npm install babel-codemod · libregistry