chalk/chalk

TypeError: Cannot read properties of undefined (reading 'bold')

duckytutorials opened this issue · 7 comments

When i do
chalk.bold.red or chalk.red.bold its broken
i m on v4.1.2 as i use common js

Qix- commented

its broken

You need to show us your

  1. Code (including the chalk import)
  2. package.json
  3. node --version
  4. npm --version
  5. The error message - and if there is no error message, please state "there is no error message" and tell us the intended output vs the output you're seeing.
  6. Screenshots if it's a coloring issue
  7. The output of echo $TERM on non-Windows machines
  8. Which terminal emulator (cmd.exe, iTerm2, xterm, etc.) you're using.

There's literally nothing I can do to help you without the above information because chalk.red.bold works for millions of other people.

Issues like this usually come from an incorrectly configured bundler.

Qix- commented

Yeah. Going to close for now as this is almost certainly not an issue with Chalk. Please let me know if that's not the case and we can re-open if need be.

Not sure if this is what OP saw, but:

All properties seem to be undefined when stdout is not a tty (including e.g. chalk.stderr).

Code:

import chalk from 'chalk-template';
console.warn(chalk.stderr.red.bold`An error`);

No bundler, in rollup.config.mjs

Qix- commented

Because you're using chalk-template. That's not how it works.

import chalk from 'chalk-template';

console.warn(chalk`{bold.red An error}`);

@Qix- it works normally, and I was expecting the chalk-template package to still allow regular usage (maybe mixing styles isn't good style, but it will happen).

Also how am I supposed to use chalk.stderr from chalk-template? It's still the same error.

Qix- commented

I don't think we have a way, come to think of it. Feel free to open an issue on chalk-template.