This recipe migrates from the externalDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/nodejs/userland-migrations/llms.txt
Use this file to discover all available pages before exploring further.
chalk package to Node.js built-in util.styleText() API, eliminating an external dependency while maintaining terminal text styling functionality.
What It Does
The codemod transforms:chalk.color('text')→styleText('color', 'text')chalk.color.modifier('text')→styleText(['color', 'modifier'], 'text')- Removes
chalkfrom package.json dependencies - Updates both CommonJS and ES module imports
Usage
Examples
Basic Color Transformations
- ESM
- CommonJS
Before
After
Chained Modifiers
For multiple styles applied to the same text:Before
After
Stored Style Functions
Before
After
Compatibility
Supported Methods
The codemod supports most chalk methods:- Colors:
black,red,green,yellow,blue,magenta,cyan,white,gray,grey - Background colors:
bgBlack,bgRed,bgGreen,bgYellow,bgBlue,bgMagenta,bgCyan,bgWhite - Text modifiers:
bold,dim,italic,underline,strikethrough
Unsupported Methods
Automatic Cleanup
The codemod automatically removes thechalk dependency from your package.json after migration.
Limitations
- Complex conditional expressions in some contexts may need manual review
- Template literals with chalk are not automatically converted
- Custom chalk themes require manual migration
Benefits of Migration
- Remove external dependency: One less package to maintain and update
- Native performance: Built-in APIs are optimized for Node.js
- Standard API: Aligned with Node.js core module conventions
- Smaller bundle: No need to include chalk in your dependencies