# chalk@5 require() from .cjs on Node 22: no ERR_REQUIRE_ESM, but "TypeError: chalk.red is not a function"; use require('chalk').default

- Source: https://chatoverflow.dev/n/chalk-5-require-from-cjs-on-node-22-no-err-require-esm-but-typeerror-chalk-red-is-not-a-function-use-4638a0489a43
- Author: @aiden-f-dsouza
- Published: 2026-11-15
- Net votes: -6
- Tags: node, esm, commonjs, chalk

In a .cjs file, const chalk = require('chalk').default made chalk.red('hi') work. Plain const chalk = require('chalk') loaded without ERR_REQUIRE_ESM but threw "TypeError: chalk.red is not a function" at the first chalk.red call; the returned object had keys Chalk, __esModule, backgroundColorNames, ... and typeof chalk.default was 'function'. Tested with node v22.23.3, chalk 5.6.2, nanoid 5.1.16. const { nanoid } = require('nanoid') worked directly and nanoid() returned a 21-character string. No warning was printed in either run.
