Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions apps/site/authors.json
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,11 @@
"name": "Richard Lau",
"website": "https://github.com/richardlau"
},
"Richie McColl": {
"id": "richiemccoll",
"name": "Richie McColl",
"website": "https://github.com/richiemccoll"
},
"Robin Bender Ginn": {
"id": "rginn",
"name": "Robin Bender Ginn",
Expand Down
82 changes: 82 additions & 0 deletions apps/site/pages/en/blog/migrations/chalk-to-styletext.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
---
date: '2026-01-19T00:00:00.000Z'
category: migrations
title: Chalk to Node.js util styleText
layout: blog-post
author: richiemccoll
---

# Migrate from Chalk to Node.js util styleText

## `chalk-to-util-styletext`

This codemod aims to help you reduce external dependencies by transforming chalk method calls to use the native Node.js styling functionality. It will also handle automatic removal of the [`chalk`](https://github.com/chalk/chalk) package from the package.json.

### Compatible Features:

- Basic colors (red, green, blue, yellow, etc.)
- Bright colors (redBright, greenBright, etc.)
- Background colors (bgRed, bgGreen, etc.)
- Text modifiers (bold, dim, italic, underline, strikethrough, etc.)
- Style chaining via array syntax
- Environment variable support (NO_COLOR, NODE_DISABLE_COLORS, FORCE_COLOR)

### Non-Compatible Features:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
### Non-Compatible Features:
### Incompatible Features:

?


- Custom RGB colors (chalk.rgb(), chalk.hex())
- 256-color palette (chalk.ansi256())
- Template literal syntax (chalk...``)
- Advanced modifiers with limited terminal support (overline, blink, etc.)

### Prerequisites:

#### Node.js Version Requirements

- Node.js v20.12.0 or later (for util.styleText)
- `util.styleText` became stable in Node.js v22.13.0 (and v23.5.0)

> If your package supports a version earlier than 22, this creates a breaking change, which means you must bump the major version of your package.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't it mean they can't do it?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They can but it's not a good practice

Copy link
Member

@JakobJingleheimer JakobJingleheimer Jan 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean if they migrate to a node API that doesn't exist in the older but "supported" version of node, it will blow up in that version.

That's more than a breaking change—that's a broken change.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JakobJingleheimer @AugustinMauroy what about something like this:

If your package currently supports Node.js versions earlier than v20.12.0, you cannot migrate to util.styleText without dropping support for those versions. This requires bumping the major version of your package AND updating the engines field in your package.json to require Node.js >= v20.12.0.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for me it's good idea


### Usage:

The source code for this codemod can be found in the [chalk-to-util-styletext directory](https://github.com/nodejs/userland-migrations/tree/main/recipes/chalk-to-util-styletext).

You can find this codemod in the [Codemod Registry](https://app.codemod.com/registry/@nodejs/chalk-to-util-styletext).

```bash
npx codemod @nodejs/chalk-to-util-styletext
```

### Example:

```js displayName="Before"
import chalk from 'chalk';

console.log(chalk.red('Error message'));

console.log(chalk.red.bold('Important error'));

const red = chalk.red;
console.log(red('Error'));

const boldBlue = chalk.blue.bold;
console.log(boldBlue('Info'));
```

```js displayName="After"
import { styleText } from 'node:util';

console.log(styleText('red', 'Error message'));

console.log(styleText(['red', 'bold'], 'Important error'));

const red = text => styleText('red', text);
console.log(red('Error'));

const boldBlue = text => styleText(['blue', 'bold'], text);
console.log(boldBlue('Info'));
```

## Recognition

We would like to thank the maintainers of [`chalk`](https://github.com/chalk/chalk) for their support of the package over time and for its contributions to the ecosystem.
Loading