Skip to content

process.stdout/stderr.isTTY undefined in worker_thread #26946

Description

@mdouglass
  • Version: v11.12.0
  • Platform: macOS Mojave 10.14.4 (Darwin brewster.local 18.5.0 Darwin Kernel Version 18.5.0: Mon Mar 11 20:40:32 PDT 2019; root:xnu-4903.251.3~3/RELEASE_X86_64 x86_64)
  • Subsystem: worker_threads

In worker threads, process.stdout.isTTY and process.stderr.isTTY are undefined.

const { Worker, isMainThread } = require('worker_threads')
if (isMainThread) {
  console.log('mainThread, process.stdout.isTTY', process.stdout.isTTY)
  console.log('mainThread, process.stderr.isTTY', process.stderr.isTTY)
  new Worker(__filename)
} else {
  console.log('workerThread, process.stdout.isTTY', process.stdout.isTTY)
  console.log('workerThread, process.stderr.isTTY', process.stderr.isTTY)
}
$ node ./main.js 
mainThread, process.stdout.isTTY true
mainThread, process.stderr.isTTY true
workerThread, process.stdout.isTTY undefined
workerThread, process.stderr.isTTY undefined

I am not sure if this is intended behavior or not, but I found it while looking into why supports-color reports that color is not supported from worker threads (see chalk/supports-color#97). If I ignore the isTTY flag, then color output does seem to work correctly.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    workerIssues and PRs related to the worker_threads module and Worker API.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions