chalk known bugs
npm21 known bugs in chalk, with affected versions, fixes and workarounds. Sourced from upstream issue trackers.
21
bugs
Known bugs
| Severity | Affected | Fixed in | Title | Status | Source |
|---|---|---|---|---|---|
| medium | any | \u2014 | `reset` order inconsistency This outputs in yellow:
``` js
console.log(chalk.yellow.reset('unicorn'));
```
This without a style:
``` js
console.log(chalk.reset.yellow('unicorn'));
```
Our docs say the styles aren't order dependent, but with reset they clearly are.
@jbnicolai thoughts on how this should be handled?
| fixed | github:41 |
| medium | 2.0.0 | \u2014 | AppVeyor (Windows) throws `Cannot read property 'toLowerCase' of undefined` Via a chalk 2.0.0 pull request I'm seeing ~300 instances of the following error for stylelint on our Windows AppVeyor builds:
```shell
FAIL lib\rules\selector-max-empty-lines\__tests__\index.js
● Test suite failed to run
TypeError: Cannot read property 'toLowerCase' of undefined
at Object.<anonymous> (node_modules/chalk/index.js:8:78)
at Object.<anonymous> (lib/formatters/stringFormatter.js:5:15)
at Object.<anonymous> (lib/formatters/index.js:5:11)
FAIL lib\rules\selector-no-qualifying-type\__tests__\index.js
```
• chalk ref: https://github.com/chalk/chalk/blob/master/index.js#L8
• stylelint AppVeyor build: https://ci.appveyor.com/project/stylelint/stylelint/build/4476
• stylelint pull request / issue: https://github.com/stylelint/stylelint/pull/2695
| fixed | github:164 |
| medium | any | \u2014 | Truecolor methods crash when color is unsupported When `supports-color` returns `false`, `supportsColor.level` equals `undefined` here: https://github.com/chalk/chalk/blob/master/index.js#L22. This makes `this.level` equal `undefined` here https://github.com/chalk/chalk/blob/master/index.js#L75 and as a result, crashes when color is unsupported. This can be reproduced by executing a script with chalk output using `child_process.spawn()` and piping output to stdout.
The fix is to change this:
```js
obj.level = options.level === undefined ? supportsColor.level : options.level;
```
to this:
```js
obj.level = options.level === undefined ? (supportsColor.level || 0) : options.level;
```
I stumbled upon this issue when tests were passing in terminal and on Travis CI, but were failing when run by `np`.
I submitted a PR with a failing test here https://github.com/chalk/chalk/pull/174. If I didn't miss anything, I will modify this PR to fix the problem.
Note, that "regular" (e.g. `chalk.blue()`) methods don't fail. | fixed | github:175 |
| medium | 8.1.2 | \u2014 | Got a error when use `chalk.bgHex()` with arg `--no-color` ```js
const chalk = require('chalk');
try {
chalk.bgHex('#cccccc')('message');
} catch (ex) {
console.error(ex);
}
```
```bash
E:\work\gulp-reporter (master) ([email protected])
$ node -v
v8.1.2
E:\work\gulp-reporter (master) ([email protected])
$ node test.js --no-color
TypeError: Cannot read property 'hex' of undefined
at Function.<anonymous> (E:\work\gulp-reporter\node_modules\chalk\index.js:98:57)
at errors.map (E:\work\gulp-reporter\lib\formater.js:240:19)
at Array.map (native)
at formater (E:\work\gulp-reporter\lib\formater.js:235:18)
at reporter (E:\work\gulp-reporter\lib\reporter.js:20:10)
at getErrors.then.errors (E:\work\gulp-reporter\lib\gulp-plugin.js:19:19)
``` | fixed | github:176 |
| medium | any | \u2014 | Newline character (\n) in tagged template literals becomes "n" From the comment here: https://github.com/chalk/chalk/issues/12#issuecomment-315685346
> When using tagged template literals, `\n` does not work => `n` is output and there is no line break.
I just ran into this myself, so I figured I'd do as @Qix- asked.
------
It looks like part of your processing is eating the `\`. Multi-line template literals (or anything similar in other languages) always seem like a cool idea until you have code like this...
```js
function run() {
if (something) {
if (somethingElse) {
console.log(`this is the first line
this is the second`);
}
}
}
```
...producing the output...
```
this is the first line
this is the second
```
...which isn't optimal. You could pull the second line all the way to the margin, but that'd never fly with formatters or linters.
Maybe there's a better way for chalk to detect character escapes (certain character escapes) and not eat them?
As a workaround, it is possible to do something like this, though it's not very attractive:
```js
console.log(chalk`{red NO} but...${'\n'}really, {green YES}`);
``` | fixed | github:177 |
| medium | any | \u2014 | The {} placeholder removes the linebreak that's just before it In a multiline chalk template string, the {} placeholder removes the linebreak that's just before it (i.e. if it is at the beginning of any line).
So for example:
```
chalk`The first line
{red The second line in red}`
```
produces:
```
The first lineThe second line in red
```
when it should produce:
```
The first line
The second line in red
```
This bug does not happen if the {} placeholder is located anywhere after the beginning of a line.
I don't know if this is related to #177 or #12 but at first glance this seems like a distinct bug to me. | fixed | github:184 |
| medium | any | \u2014 | Root chalk function doesn't support multiple arguments if used in template mode When creating a chalk object with template functionality:
```javascript
const ctx = chalk.constructor({level: 0}); // no new; templates enabled
```
calling a style with multiple arguments will concatenate them with spaces
```javascript
const str = ctx.red('hello', 'there'); //-> "hello there"
```
but calling the root function doesn't:
```javascript
const str = ctx('hello', 'there'); // -> "hello"
``` | fixed | github:187 |
| medium | any | \u2014 | Should we match console.log(fmt, ...) formatting with chalk? Right now, we do a simple `.join(' ')` on arguments. While this covers most cases, this isn't 100% analogous to `console.xxx()` functions.
Under the hood, the `console.xxx()` functions use [`util.format()`](https://nodejs.org/api/util.html#util_util_format_format_args).
Should we be using it?
// cc @sindresorhus | fixed | github:189 |
| medium | any | \u2014 | Interpolated template expressions that evaluate to `undefined` or `null` throw exception Getting the following error message with template literals:
```
> chalk`hello ${undefined}`
TypeError: Cannot read property 'toString' of undefined
at chalkTag (/src/bitlang/bootstrap/node_modules/chalk/index.js:210:25)
at Chalk.chalk.template (/src/bitlang/bootstrap/node_modules/chalk/index.js:36:20)
``` | fixed | github:194 |
| medium | 2.3.0 | \u2014 | chalk.enabled=true or { enabled: true} does not work when color support is initially detected as false <!-- Issuehunt Badges -->
[<img alt="Issuehunt badges" src="https://img.shields.io/badge/IssueHunt-%2440%20Rewarded-%237E24E3.svg" />](https://issuehunt.io/r/chalk/chalk/issues/234)
<!-- /Issuehunt Badges -->
## Environment
**Chalk:** 2.3.0
**Node.js:** 6.12.0 and 8.9.3
## Issue
**chalk.js**
```js
const chalk = require('chalk');
chalk.enabled = true;
console.log(chalk`{green hello}`);
```
--or--
```js
const chalk = new require('chalk').constructor({ enabled: true });
```
If you run **chalk.js** as:
```
node chalk.js
```
The output is a green `hello`.
If you run this in a clean environment (which causes **supports-color** to report that colors are not supported):
```
env -i node chalk.js
```
The output is a un-colored `hello`.
## Details
I traced this to https://github.com/chalk/chalk/blob/master/index.js#L177, where `this.enabled` is `false`, and `this` is `builder`. It seems like, somehow, the initial value for `enabled` is not getting changed or is not filtering down to the `enabled` property defined on `builder`.
As expected, using the environment variable `FORCE_COLOR` or the `--color` parameter does work, as it gets `enabled` to the right value, initially.
Interestingly, running it as (to force it on from the start):
```
env -i node chalk.js --color
```
...and then doing:
```js
chalk.enabled = false;
```
..._does_ actually turn it off. Now I'm thinking there's some issue with truthy and falsy. I'm not sure.
## Aside
It would definitely be easier for me to dig more on this if there weren't _so much_ indirection in the way this is implemented :innocent:; but, I'm sure some or most of that is necessary to get this to work so cleanly.
<!-- Issuehunt content -->
---
<details>
<summary>
<b>IssueHunt Summary</b>
</summary>
#### [<img src='https://avatars2.githubusercontent.com/u/885648?v=4' alt='qix-' width=24 height=24> qix-](https://issuehunt.io/u/qix-) has been rewarded.
### Backers (Total: $40.00)
- [<img src='https://avatars3.githubusercontent.com/u/44827199?v=4' alt='issuehunt' width=24 height=24> issuehunt](https://issuehunt.io/u/issuehunt) ($40.00)
### Submitted pull Requests
- [#356 Remove the `.enabled` property in favor of `.level`](https://issuehunt.io/r/chalk/chalk/pull/356)
---
### Tips
- Checkout the [Issuehunt explorer](https://issuehunt.io/r/chalk/chalk/) to discover more funded issues.
- Need some help from other developers? [Add your repositories](https://issuehunt.io/r/new) on IssueHunt to raise funds.
---
IssueHunt has been backed by the following sponsors. [Become a sponsor](https://issuehunt.io/membership/members)
</details>
<!-- /Issuehunt content--> | fixed | github:234 |
| medium | 2.3.0 | \u2014 | Cannot read property 'hex' of undefined (only with v2.3.0) Hi,
I use `chalk` to add colors to console logs in a personal project ([create-cozy-app](https://github.com/CPatchane/create-cozy-app)) and thanks a lot for your great job on this module 👍
But something seems broken since the version 2.3.0. I use almost only the `chalk.hex()` method and I got this issue:
```
myapptest/node_modules/cozy-scripts/node_modules/chalk/index.js:82
const open = ansiStyles.color[levelMapping[level]][model].apply(null, arguments);
^
TypeError: Cannot read property 'hex' of undefined
at Function.<anonymous> (myapptest/node_modules/cozy-scripts/node_modules/chalk/index.js:82:55)
at Object.<anonymous> (myapptest/node_modules/cozy-scripts/utils/_colorize.js:7:15)
at Module._compile (module.js:643:30)
at Object.Module._extensions..js (module.js:654:10)
at Module.load (module.js:556:32)
at tryModuleLoad (module.js:499:12)
at Function.Module._load (module.js:491:3)
at Module.require (module.js:587:17)
at require (internal/module.js:11:18)
```
All work well with the version 2.2.2 but also if I only use default colors (`chalk.blue()`, `chalk.bgWhite()`). And it seems to concern only my webpack usage like [here](https://github.com/CPatchane/create-cozy-app/blob/master/packages/cozy-scripts/config/webpack.config.progress.js#L16) or [here](https://github.com/CPatchane/create-cozy-app/blob/master/packages/cozy-scripts/scripts/watch.js#L20).
I suppose that came from this commit so: https://github.com/chalk/chalk/commit/7be154c074026f77b99e7d854b3a4cdd5e4ae502
Hope that will help. | fixed | github:248 |
| medium | any | \u2014 | Chalk doesn't detect color support for VSCode Debug Console Chalk works perfect for nearly all use cases we have and we make heavy use of testing for `chalk.enabled` to decide how we format our log output. This works in the local command line as expected and logs are printed colorfully.
Since we're switching from Atom to VSCode I've noticed that the color mode detection doesn't seem to work for the VSCode console. `chalk` reports `supportsColor` and `enabled` both being false. The VSCode Debug Console clearly supports colors and if I manually enforce `chalk` to use colors it works fine and as expected. But I wonder if this automatic detection is something that can be fixed?
| fixed | github:254 |
| medium | any | \u2014 | Add "bright black" and use "gray" as alias For consistency, it would be good to have a `chalk.blackBright` for use.
Similarly, it'd be nice if there was a "background" color alias for gray: `chalk.bgGray`. | fixed | github:257 |
| medium | 2.3.2 | \u2014 | Destructuring `hex` not working **Bug reporting**
It's not possible to destructure `hex` function.
**My code**
*Chalk version*: 2.3.2
*Node version*: 9.4
```js
const {hex} = require('chalk');
hex('#013370')('strapi');
```
**Error output**
```shell
TypeError: Cannot read property '_styles' of undefined
at ./node_modules/chalk/index.js:88:34
``` | fixed | github:271 |
| medium | any | \u2014 | Nested `.dim()` affects surrounding styles too It seems `dim` doesn't handle being nested inside another style:
The following:
```js
const chalk = require('chalk');
console.log(chalk.bold(chalk.dim('bold-dim'), 'bold'));
```
Produces:
<img width="225" alt="screen shot 2018-08-03 at 00 44 28" src="https://user-images.githubusercontent.com/170270/43601020-68d3f2c6-96b6-11e8-86c6-0b9c14d137b5.png">
While it should produce:
<img width="221" alt="screen shot 2018-08-03 at 00 45 18" src="https://user-images.githubusercontent.com/170270/43601059-8333c3c6-96b6-11e8-828c-89c92ef14ac3.png">
I reproduced this in both Terminal.app and iTerm.app on macOS 10.13.
// @Qix- Any ideas? | fixed | github:290 |
| medium | 10.13.0 | \u2014 | Bold resets previous color Depending on order and type of operations, `bold` causes a previously set color to be suppressed:

```
chalk.bold("foo") => '\u001b[1mfoo\u001b[22m'
chalk.blue.bold("foo") => '\u001b[94m\u001b[1mfoo\u001b[22m\u001b[39m'
chalk.bold.blue("foo") => '\u001b[1m\u001b[94mfoo\u001b[39m\u001b[22m'
chalk.bold.hex("#0000ff")("foo") => '\u001b[1m\u001b[38;2;0;0;255mfoo\u001b[39m\u001b[22m'
chalk.hex("#0000ff").bold("foo") => '\u001b[38;2;0;0;255m\u001b[1mfoo\u001b[22m\u001b[39m'
```
The screenshot above was taken on Windows 10 1709 (Enterprise) using Node v10.13.0 through winpty 0.4.3 in mintty 2.8.1 installed with Git for Windows. Running node via Powershell or `cmd` yields identical ANSI sequences and similar results, as far as the coloration of the last sample is concerned, e.g.:

| fixed | github:325 |
| medium | any | \u2014 | Nesting bug <!-- Issuehunt Badges -->
[<img alt="Issuehunt badges" src="https://img.shields.io/badge/IssueHunt-%2480%20Rewarded-%237E24E3.svg" />](https://issuehunt.io/r/chalk/chalk/issues/334)
<!-- /Issuehunt Badges -->
If the bug mention in https://github.com/doowb/ansi-colors#nested-styling-bug is valid, we should fix it.
<!-- Issuehunt content -->
---
<details>
<summary>
<b>IssueHunt Summary</b>
</summary>
#### [<img src='https://avatars2.githubusercontent.com/u/2047945?v=4' alt='farnabaz' width=24 height=24> farnabaz](https://issuehunt.io/u/farnabaz) has been rewarded.
### Backers (Total: $80.00)
- [<img src='https://avatars3.githubusercontent.com/u/44827199?v=4' alt='issuehunt' width=24 height=24> issuehunt](https://issuehunt.io/u/issuehunt) ($80.00)
### Submitted pull Requests
- [#335 fix(nested-styling): reopen closed style](https://issuehunt.io/r/chalk/chalk/pull/335)
---
### Tips
- Checkout the [Issuehunt explorer](https://issuehunt.io/r/chalk/chalk/) to discover more funded issues.
- Need some help from other developers? [Add your repositories](https://issuehunt.io/r/new) on IssueHunt to raise funds.
---
IssueHunt has been backed by the following sponsors. [Become a sponsor](https://issuehunt.io/membership/members)
</details>
<!-- /Issuehunt content--> | fixed | github:334 |
| medium | any | \u2014 | number to string casting (typescript: not assignable) ```typescript
// PLS do number to string casting automatically
console.log(chalk`{yellowBright ${i.toString()} tries}`)
```
ATM it throws a not assignable error when using without .toString() | fixed | github:338 |
| medium | any | \u2014 | Template literals are unsupported for nested calls <!-- Issuehunt Badges -->
[<img alt="Issuehunt badges" src="https://img.shields.io/badge/IssueHunt-%2440%20Rewarded-%237E24E3.svg" />](https://issuehunt.io/r/chalk/chalk/issues/341)
<!-- /Issuehunt Badges -->
The following is unsupported despite it being allowed by the type system:
```ts
chalk.bold`Hello, {cyan.inverse ${name}!} This is a test. {green ${exclamation}!}`;
```
Produces:
```
Hello, {cyan.inverse ,!} This is a test. {green ,!} Sindre Neat
```
Instead of:
```
Hello, Sindre! This is a test. Neat!
```
<!-- Issuehunt content -->
---
<details>
<summary>
<b>IssueHunt Summary</b>
</summary>
#### [<img src='https://avatars0.githubusercontent.com/u/9020072?v=4' alt='toonijn' width=24 height=24> toonijn](https://issuehunt.io/u/toonijn) has been rewarded.
### Backers (Total: $40.00)
- [<img src='https://avatars3.githubusercontent.com/u/44827199?v=4' alt='issuehunt' width=24 height=24> issuehunt](https://issuehunt.io/u/issuehunt) ($40.00)
### Submitted pull Requests
- [#392 Support for template literals for nested calls](https://issuehunt.io/r/chalk/chalk/pull/392)
- [#398 Support nested calls](https://issuehunt.io/r/chalk/chalk/pull/398)
---
### Tips
- Checkout the [Issuehunt explorer](https://issuehunt.io/r/chalk/chalk/) to discover more funded issues.
- Need some help from other developers? [Add your repositories](https://issuehunt.io/r/new) on IssueHunt to raise funds.
</details>
<!-- /Issuehunt content--> | fixed | github:341 |
| medium | any | \u2014 | Bug: bracketed Unicode escapes not supported <!-- Issuehunt Badges -->
[<img alt="Issuehunt badges" src="https://img.shields.io/badge/IssueHunt-%2450%20Rewarded-%237E24E3.svg" />](https://issuehunt.io/r/chalk/chalk/issues/349)
<!-- /Issuehunt Badges -->
Repro:
```js
// example.js
const chalk = require('chalk')
console.log(chalk`\u{2192} Running test {bold foo}...`)
```
Expected output:
<pre><code>→ Running test <strong>foo</strong>...</code></pre>
Actual output:
```
Error: Found extraneous } in Chalk template literal
at node_modules/chalk/templates.js:109:11
at String.replace (<anonymous>)
at module.exports (node_modules/chalk/templates.js:99:6)
at chalkTag (node_modules/chalk/index.js:221:9)
at Chalk.chalk.template (node_modules/chalk/index.js:36:20)
at Object.<anonymous> (example.js:3:17)
```
<!-- Issuehunt content -->
---
<details>
<summary>
<b>IssueHunt Summary</b>
</summary>
#### [<img src='https://avatars2.githubusercontent.com/u/885648?v=4' alt='qix-' width=24 height=24> qix-](https://issuehunt.io/u/qix-) has been rewarded.
### Backers (Total: $50.00)
- [<img src='https://avatars3.githubusercontent.com/u/44827199?v=4' alt='issuehunt' width=24 height=24> issuehunt](https://issuehunt.io/u/issuehunt) ($50.00)
### Submitted pull Requests
- [#350 Fix bracketed unicode escapes in template literals](https://issuehunt.io/r/chalk/chalk/pull/350)
---
### Tips
- Checkout the [Issuehunt explorer](https://issuehunt.io/r/chalk/chalk/) to discover more funded issues.
- Need some help from other developers? [Add your repositories](https://issuehunt.io/r/new) on IssueHunt to raise funds.
---
IssueHunt has been backed by the following sponsors. [Become a sponsor](https://issuehunt.io/membership/members)
</details>
<!-- /Issuehunt content--> | fixed | github:349 |
| medium | any | \u2014 | Malicious code in chalk (npm) The package was compromised and malicious code added.
---
_-= Per source details. Do not edit below this line.=-_
## Source: ghsa-malware (985b6546ed08c8482326a4819faec318c27c1f6d7518acdf384d5f5a8c1453aa)
Any computer that has this package installed or running should be considered fully compromised. All secrets and keys stored on that computer should be rotated immediately from a different computer. The package should be removed, but as full control of the computer may have been given to an outside entity, there is no guarantee that removing the package will remove all malicious software resulting from installing it.
| open | osv:MAL-2025-46969 |
API access
Get this data programmatically \u2014 free, no authentication.
curl https://depscope.dev/api/bugs/npm/chalk