npm Community Forum (Archive)

The npm community forum has been discontinued.

To discuss usage of npm, visit the GitHub Support Community.

npm@6.2.0 audit always prints ANSI escape codes, even when output is not a TTY

What I Wanted to Do

I attempted to pipe the output of npm audit into the clipboard / a file via running npm audit | pbcopy. I expected the output to be without ANSI escape formatting.

What Happened Instead

The output contained ANSI escape formatting, so it’s unreadable in a text editor.

Reproduction Steps

Using npm@6.2.0, run npm audit | pbcopy or npm audit > file.txt.


Using git bisect, I’ve narrowed this into having been introduced in Unfortunately, since that’s a megacommit that touched many (all?) of npm’s dependencies, it’s not clear to me what precisely caused this. This bug isn’t present in npm@6.1.0.

I attempted to include sample attachments, but the forum won’t let me because this is a new account. Here’s a short clip from each.


=== npm audit security report ===                        
# Run  npm install npm-audit-report@1.3.1  to resolve 1 vulnerability


e[90m                                                                                e[39m
e[90m e[39m                      === npm audit security report ===                       e[90m e[39m
e[90m                                                                                e[39m
# Run  npm install npm-audit-report@1.3.1  to resolve 1 vulnerability

Platform Info

$ npm --versions
{ npm: '6.2.0',
  ares: '1.14.0',
  cldr: '33.1',
  http_parser: '2.8.0',
  icu: '62.1',
  modules: '64',
  napi: '3',
  nghttp2: '1.32.0',
  node: '10.7.0',
  openssl: '1.1.0h',
  tz: '2018e',
  unicode: '11.0',
  uv: '1.22.0',
  v8: '',
  zlib: '1.2.11' }
$ node -p process.platform

Triage note: I’m so skeptical about that bisect. That’s super weird? That said, we only avoid color if you do --no-color or NO_COLOR=true npm ...? Have we ever avoided this on TTY? :thinking:

Just tested, and this also occurs in the just-released 6.3.0.

I can reproduce this.

It’s worth noting that it does disable color when writing to a non-tty, but still outputs some other ANSI codes that aren’t displayed. This is caused by a bug in the colors module used by cli-table2 and cli-table3 that got updated when we were flattening. For the time being I’ll pin us back.