chalk: It's not working on my mac (10.11.5)

This is my code:

const chalk = require('chalk');

console.log(chalk.red('TOTOTOTOT'));
console.log(chalk.blue('Hello world!'));

It just prints white text in iTerm and Terminal

package.json

"chalk": "^1.1.3",

What am I doing wrong here?

Thanks

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 20 (8 by maintainers)

Most upvoted comments

When you run your script, run it like this:

$ FORCE_COLOR=1 node /path/to/your/script.js

Does it output color?

Yes. The child process is piped to the parent process which makes isatty() return 0 (false) within the child process, shutting off colored output thanks to supports-color returning a false-ey result.

Pass an env entry with FORCE_COLOR=1 to the child.

Some pseudo-code:

child_process = ...

if chalk.supportsColor then
    child_process.env.FORCE_COLOR = '1'
endif

That should get you what you want (barring weird edge-cases).

Hope that helps 💃