Using in non-tty environment giving errors
See original GitHub issueI am using this cli tool in lerna, which is not using tty channel to spawn child process for running npm scripts. In that case, the chalk
command always faile with error code 1
Invalid style: THE_STRING_I_WANT_TO_LOG
Further investigate indicates if not using tty, this package is using getStdin
from get-stdin
to get the input, and trying to process all input as style. This is wrong as the data I want to print is also part of styles
array, which is not a preset style, hence the error.
Run this in any non-tty process and you can reproduce the issue.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:3
- Comments:13 (6 by maintainers)
Top Results From Across the Web
Crash if missing parameter in non-tty environment without ...
If a parameter is missing when doing a resource group template deploy, az attempts to prompt, but crashes upon finding it's not in...
Read more >Error: Cannot perform an interactive login from a non TTY device
I played with some settings that are already in the mobaxterm, but none worked. /home/mobaxterm>docker login abcdef.azurecr.io Error: Cannot ...
Read more >aws ecr saying "Cannot perform an interactive login from a ...
Error : Cannot perform an interactive login from a non TTY device I am using Jenkins Pipeline. Any Idea how it can be...
Read more >Solved: Piplenes: docker login can not perform an interact...
Solved: I am trying to push the build docker image from within pipeline to docker hub and get and error: == + docker...
Read more >sudo: no tty present and no askpass program specified
The error message sudo: no tty present and no askpass program specified will occur when the sudo command is trying to execute a...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Alright figured it out. To work around this, pass
--no-stdin
directly afterchalk
.(You also need to add
{stdio: 'inherit'}
but that isn’t due to this library in any way).In your repro, that looks like this:
@sindresorhus I think
meow
is handling stdin all wrong, to be completely fair with you.--no-stdin
is very much not a common unix pattern.This is 1) undocumented as per our help docs, 2) not really a common unix-ey thing, 3) mishandles stdin if the option is accidentally omitted, clearly with a confusing effect. Not sure what the best course of action is aside from dropping
meow
and going with something a bit lighter weight.I had also tagged this as “bug” but… I guess it’s not, if we’re going by how
meow
expects CLIs to work… not sure what to think about that.@sindresorhus
What is the intended behavior of this conditional? It’s the culprit here. There is no great way to detect if the user wants stdin consumption without having them specify it.
https://github.com/chalk/chalk-cli/blob/932d798cdce67d9e28f4b40fa9446a5ae0a8a52c/cli.js#L78
The fix here would be to allow passing
-
as the “input” or otherwise passing a new--stdin, -s
flag that indicates stdin should be used as the input. My preference is the latter as it’s easier to discern between wanting stdin to parse and a literal-
to display.