{"id":18981,"library":"babel-codemod","title":"babel-codemod","description":"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.","status":"maintenance","version":"2.1.2","language":"javascript","source_language":"en","source_url":"https://github.com/square/babel-codemod","tags":["javascript"],"install":[{"cmd":"npm install babel-codemod","lang":"bash","label":"npm"},{"cmd":"yarn add babel-codemod","lang":"bash","label":"yarn"},{"cmd":"pnpm add babel-codemod","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Core Babel compilation engine","package":"@babel/core","optional":false},{"reason":"Parses JavaScript/TypeScript into AST","package":"@babel/parser","optional":false},{"reason":"Preserves original formatting when printing transformed code","package":"recast","optional":false},{"reason":"Transpiles plugin code using latest Babel plugins","package":"@babel/preset-env","optional":true},{"reason":"Experimental TypeScript support for plugin code","package":"@babel/preset-typescript","optional":true}],"imports":[{"note":"CLI is invoked via `codemod` command or npx. No programmatic API is exposed by default.","wrong":"babel-codemod --plugin my-plugin src/ (without npx if not globally installed)","symbol":"codemod (CLI)","correct":"npx babel-codemod --plugin my-plugin src/"},{"note":"babel-codemod is CLI-only; there is no programmatic API. Plugins are standard Babel plugins.","wrong":"Importing babel-codemod as a library in code","symbol":"babel plugin as codemod","correct":"// Use any Babel plugin directly via --plugin flag"}],"quickstart":{"code":"# Install globally or use npx\nnpm install -g babel-codemod\n# Run a Babel plugin on a file\ncodemod --plugin @babel/plugin-transform-arrow-functions src/index.js\n# Run a remote plugin from AST Explorer (use with caution)\ncodemod --remote-plugin https://astexplorer.net/#/gist/... src/\n# Use local plugin with custom babel config\ncodemod --find-babel-config --plugin ./my-plugin.js src/","lang":"javascript","description":"Demonstrates installing babel-codemod and running a Babel plugin on files, including local and remote plugin usage."},"warnings":[{"fix":"Avoid using --remote-plugin with untrusted URLs.","message":"Remote plugins execute with full user privileges; only use trusted sources to avoid security risks.","severity":"gotcha","affected_versions":">=2.0.0"},{"fix":"Ensure all plugins are written for Babel 7. Use @babel/plugin-* packages.","message":"Version 2.0.0 upgraded to Babel 7; plugins must be compatible with Babel 7 API.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Check babel issues for TypeScript support gaps.","message":"TypeScript support is experimental via @babel/preset-typescript; not all valid TypeScript is supported.","severity":"gotcha","affected_versions":">=2.0.0"},{"fix":"Prepare to migrate to official TypeScript compiler if needed.","message":"Experimental TypeScript transpilation may be removed in future versions.","severity":"deprecated","affected_versions":">=2.0.0"},{"fix":"Ensure .babelrc is present and all referenced presets/plugins are installed locally.","message":"When using --find-babel-config, .babelrc lookup rules apply; missing config may cause unexpected behavior.","severity":"gotcha","affected_versions":">=2.0.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"npm install @babel/parser or upgrade to v2.1.2+ that explicitly depends on it.","cause":"Missing dependency @babel/parser required since v2.1.1","error":"Error: Cannot find module '@babel/parser'"},{"fix":"Use @babel/plugin-* packages for Babel 7, or downgrade to babel-codemod v1.x.","cause":"Using a Babel 6 plugin with babel-codemod v2.x which expects Babel 7 plugins","error":"Error: Requires Babel 7, but found Babel 6"},{"fix":"Ensure the plugin exports a function that returns a visitor object.","cause":"Invalid plugin syntax or plugin not exporting a function","error":"TypeError: Cannot read property 'parse' of undefined"},{"fix":"Create a .babelrc file with the desired plugins/presets, or remove --find-babel-config.","cause":"No .babelrc or babel.config.js found in the project","error":"Error: No babel config found, but --find-babel-config flag used"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}