electron: Terminal colors are not supported through electron in Windows

  • Electron version: 1.7.10
  • Operating system: Windows

Expected behavior

When running in regular node (not electron) colors are supported and output correctly

node index.js

screen shot 2017-12-20 at 1 25 26 pm

When running in electron colors are not supported and do not output correctly

.\node_modules\.bin\electron .

screen shot 2017-12-20 at 1 25 43 pm

How to reproduce

My code…

//index.js
console.log(process.versions)
console.log(require('chalk').red('hi there'))
console.log(require('supports-color'))

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 3
  • Comments: 15 (4 by maintainers)

Most upvoted comments

Hi I’m having the same issue with electron 8.0.1 And windows 10.

To recreate - create a new project with electron / chalk - using these:

package.json

{
  "name": "electron-colors",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "start": "electron index.js"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "chalk": "^3.0.0",
    "electron": "^8.0.1"
  }
}

index.js

const chalk = require("chalk");

console.log("Chalk supported?", chalk.supportsColor, "\n",
 "Electron version", chalk.green(process.versions.electron), "\n",
    "OS Version",  chalk.blue(process.getSystemVersion()));

console.log("\x1b[36m%s\x1b[0m", "This will work on npm run though!");  

Then run either with npm or directly calling electron.exe you’ll see the issue on both cases. However, when running with npm the console does indeed support color if specified directly.

Using npm

C:\Users\idanwork\Projects\electron-colors>npm run start

> electron-colors@1.0.0 start C:\Users\idanwork\Projects\electron-colors
> electron index.js


Chalk supported? false
 Electron version 8.0.1
 OS Version 10.0.17134
This will work on npm run though!

image

Using electron.exe

C:\Users\idanwork\Projects\electron-colors>node_modules\.bin\electron .

Chalk supported? false
 Electron version 8.0.1
 OS Version 10.0.17134
?[36mThis will work on npm run though!?[0m

image

This is the expected result, using npm with macOS Catalina

idanwork electron-colors % npm run start

> electron-colors@1.0.0 start /Users/idanwork/Projects/electron-colors
> electron index.js

Chalk supported? { level: 3, hasBasic: true, has256: true, has16m: true } 
 Electron version 8.0.1 
 OS Version 10.15.3
This will work on npm run though!

image

image

It’s not blocked/need-info. That was removed on the 26th Feb.

This still happens on Electron v5.0.2 Windows 10. Makes the debug package not work as expected.

Issue still exists in Electron v10.1.1 Windows 10 pro OS build 19041.508

Electron v4.1.3 + Windows 7/10, still has this issue.

done

Why is this “blocked/need-info”? The example is concise and reproduceable is it not? I’m seeing the same issue, as I offer a command line version of my ElectronJS GUI for automation. I’m using electron v8.2.1.