Before you begin
Make sure you have:- Node.js installed (version 18 or higher recommended)
- A Node.js project with code you want to migrate
- Git initialized in your project directory
Your first migration
Let’s walk through running a codemod to migrate deprecatedutil.log() calls to the modern console.log() equivalent.
Commit your current work
Before running any codemod, ensure all your changes are committed to git:This allows you to easily review the changes made by the codemod and revert if necessary.
Run the codemod from the registry
Navigate to your project directory and run the migration using the Codemod CLI:The codemod will:
- Scan your project for JavaScript and TypeScript files
- Find all
util.log()calls - Transform them to
console.log()with timestamps - Remove unused imports
Example output
Example output
Test your application
Run your tests to ensure everything still works correctly:If you have integration or end-to-end tests, run those as well to verify the migration didn’t introduce any issues.
The codemod automatically handles different import styles, including CommonJS
require(), ES module import, destructured imports, and namespace imports.Running other migrations
The process is the same for any migration recipe. Just replace the recipe name:Interactive mode
By default, the Codemod CLI runs in interactive mode, allowing you to:- Preview changes before applying them
- Select which files to transform
- Skip certain transformations
Targeting specific files
You can target specific files or directories:Common migration scenarios
Migrating deprecated util.is* methods
Migrating deprecated util.is* methods
Replace all 15 deprecated This handles:
util.is*() methods with modern alternatives:util.isArray()→Array.isArray()util.isBoolean()→typeof value === 'boolean'util.isBuffer()→Buffer.isBuffer()- And 12 more methods
Updating import assertions to attributes
Updating import assertions to attributes
Convert import assertions (Node.js dropped support for import assertions in version 22.0.0, but added support for import attributes in 18.20.0.
assert syntax) to the standardized import attributes (with syntax):Migrating chalk to util.styleText
Migrating chalk to util.styleText
Replace the popular chalk package with Node.js’s built-in This migration:
util.styleText():- Converts chalk API calls to
util.styleText() - Removes chalk from
package.jsondependencies - Handles chained styles and color combinations
Fixing TypeScript import specifiers
Fixing TypeScript import specifiers
Correct import specifiers to comply with Node.js ESM requirements:Node.js ESM requires explicit file extensions, even in TypeScript projects.
Running from source
For development or testing, you can run codemods from a local clone of the repository:Troubleshooting
No files were transformed
No files were transformed
If the codemod reports no files were transformed:
- Verify your code actually uses the deprecated API
- Check that your files are in the default search paths (
**/*.js,**/*.ts, etc.) - Ensure files aren’t in
node_modules/(excluded by default) - Try running with
--verboseto see detailed output
Some transformations were skipped
Some transformations were skipped
Codemods may skip certain patterns if:
- The code is too complex to safely transform
- The API is used in an uncommon way
- Manual intervention is required
Build or tests fail after migration
Build or tests fail after migration
If your build or tests fail:
- Review the git diff carefully
- Check for any edge cases the codemod didn’t handle
- Verify that the new API is available in your Node.js version
- If needed, revert with
git reset --hard HEAD~1and file an issue
Best practices
Run one migration at a time
Don’t run multiple migrations simultaneously. Complete, test, and commit each migration before starting the next.
Review all changes
Always review the git diff before committing. Look for unexpected changes or edge cases.
Test thoroughly
Run your full test suite, including integration tests, after each migration.
Keep backups
Even with git, consider keeping a backup of critical files before large migrations.
What’s next?
Installation
Learn about advanced installation options and configuration
Browse Recipes
Explore all available migration recipes
How Codemods Work
Understand the technical details behind codemods
Contributing
Create your own migration recipes