question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Using in non-tty environment giving errors

See original GitHub issue

I 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:closed
  • Created 4 years ago
  • Reactions:3
  • Comments:13 (6 by maintainers)

github_iconTop GitHub Comments

7reactions
Qix-commented, Sep 10, 2021

Alright figured it out. To work around this, pass --no-stdin directly after chalk.

(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:

execSync('npx chalk --no-stdin yellow "expect my colorful log 1"', {stdio: 'inherit'});
> chalk-cli-issue-11@1.0.0 log
> node index.js

expect my colorful log 1

image


@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.

6reactions
Qix-commented, Sep 10, 2021

@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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found