Questions tagged [chalk]
51 questions
90
votes
11 answers
chalk - Error [ERR_REQUIRE_ESM]: require() of ES Module
Hi tried to install chalk on my very simple app and then i got error:
Error [ERR_REQUIRE_ESM]: require() of ES Module my-file-is-here and chalk\node_modules\chalk\source\index.js from my-file-is-here not supported.
Instead change the require of…

Elad87
- 941
- 1
- 3
- 8
10
votes
1 answer
Determine terminal/TTY background color at runtime
Using the chalk library to stylize/colorize the terminal.
import chalk from 'chalk';
if I use:
console.log(chalk.blue('foobar'));
that's totally readable in a terminal with a light background, but totally unreadable in a terminal with a dark…

Alexander Mills
- 90,741
- 139
- 482
- 817
9
votes
2 answers
Error: Must use import to load ES Module - Using Typescript and Node
Background
Tried to improve my error coding visibility and structure and decided to add the dependency ''' chalk ''', which requires Pure ESM. Originally, my ts.config/package.json was a common.js file and did not declare the "type" as "module".…

ASG4
- 169
- 2
- 9
8
votes
0 answers
How to apply a colour when piping stdout from a child process?
I'm using chalk to colour the output from from my command-line node application. Normally like this:
console.log(chalk.red(error));
However, I need to pipe stdout from a child process, and colour this output too:
var child =…

mtmacdonald
- 14,216
- 19
- 63
- 99
6
votes
4 answers
How would you fix an 'ERR_REQUIRE_ESM' error?
I am trying to use the chalk npm.
My code is:
const chalk = require('chalk');
console.log(
chalk.green('All sytems go') +
chalk.orange('until').underline +
chalk.black(chalk.bgRed('an error occurred'))
…

Tarneka Ezell
- 95
- 1
- 1
- 4
5
votes
2 answers
What's the difference between node:process and process?
When I import node:process it works fine. However, when I try to require the same, it gives an error.
This works fine:
import process from 'node:process';
But when I try to require the same, it throws an error:
const process =…

Udasi Tharani
- 83
- 2
- 8
5
votes
1 answer
How to get the names of all colors supported by Chalk?
I'm using the Chalk NPM package in TypeScript. If I dynamically set the color for Chalk, then I get a TS error. I could use a type assertion like chalk[color] as Chalk but I would prefer to use a type predicate if possible, which would require for…

Gary
- 3,891
- 8
- 38
- 60
5
votes
2 answers
Adding color to repl prompt (node)
I find that adding color to the prompt in repl really helps to separate the outputs. I achieved this by using NPM's chalk, but this adds a bunch of space between the prompt and the cursor.
var term = repl.start({
prompt: chalk.blue('goose> '),
…

Bill Johnston
- 1,160
- 1
- 14
- 31
4
votes
3 answers
Use node.js and ANSIcolor plugin in Jenkins
I want to display colored output in jenkins which is produced by node.js
Both work separately, but not combined:
Node Script
My test script test.js:
console.log(require("chalk").red("Node Red"))
Calling the test script in the shell works:
node…

Matthias M
- 12,906
- 17
- 87
- 116
3
votes
1 answer
How to use Jest to test a console.log that uses chalk?
Writing a Node CLI in my module I have a console.log with chalk, example:
console.log(
chalk.green(`${delta}:`),
chalk.white(`\nAPI: ${apiPath}`),
)
when I run a Jest code coverage --coverage I'm reminded that I didn't have a test so I…

DᴀʀᴛʜVᴀᴅᴇʀ
- 7,681
- 17
- 73
- 127
3
votes
1 answer
How to define TypeScript types for chalk's tagged template literal?
In chalk 2.0, it's possible to use tagged strings:
const chalk = require('chalk');
console.log(chalk`{bold some} text`);
How to amend chalk's type definitions to make TypeScript happy with it? Currently, I get:
error TS2349: Cannot invoke an…

Borek Bernard
- 50,745
- 59
- 165
- 240
3
votes
4 answers
Can't get color output in Node
I'm trying to log to the console in different colors using chalk but I haven't gotten it to work. I have a file that consists of the following two lines and I'm running it with the command node test.js
var chalk =…

spencer.sm
- 19,173
- 10
- 77
- 88
2
votes
3 answers
Dynamic call of chalk with typescript
I am using typescript and want to call the chalk method dynamically, see my code :
import chalk from 'chalk';
const color: string = "red";
const message: string = "My Title";
const light: boolean = false;
const colorName =…

Lukas Laudrain
- 436
- 3
- 10
2
votes
2 answers
Chalk won't run in Deno
The following code is from the README of the Deno Chalk library.
Deno/Typescript will not let it pass:
import chalk from "https://deno.land/x/chalk_deno@v4.1.1-deno/source/index.js";
// Run this in debugger and it's fine but it won't…

Marc
- 13,011
- 11
- 78
- 98
2
votes
2 answers
How does NodeJS module, Chalk's, chaining syntax work?
I don't understand how Chalk's (NodeJS module) syntax works (and it bothers me). I have searched far and wide for an answer, but I am not having any luck and likely don't know the technical term(s) for what I need to look for. I have tried looking…

Trevor
- 37
- 6