SBoudrias / Inquirer.js

A collection of common interactive command line user interfaces.
MIT License
20.09k stars 1.3k forks source link

Multiple Questions on Windows 10 Hangs #767

Closed jlkalberer closed 1 month ago

jlkalberer commented 5 years ago
Windows 10 - Version 1803 (OS Build 17134.523)
yarn - 1.9.4
npm - 6.0.1
node - v10.13.0

I dug into this a bit because of https://github.com/Microsoft/AppCenter-SDK-React-Native/issues/471#event-2067227003

Inquirer uses stdout to write to the command prompt. It looks like if this line is run, it will cause windows to "hang". Also, it turns out that node 8.15.0 works with this code so it could also just be a regression

I think what is really going on is that the stream is just ending so we don't see any more output.

Here is a repro of the bug.

const readline = require("readline");

let index = 0;
const runQuestion = () => {
  index += 1;
  console.log(`Question ${index} - type something`);

  const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
  });

  rl.on("line", line => {
    console.log(`Received: ${line}`);

    rl.output.end();
    rl.pause();
    rl.close();

    runQuestion();
  });
};

runQuestion();

With this simple example removing rl.output.end() fixes things but the only way to work around it in inquirer is to remove the rl.close() line.

mshima commented 4 years ago

@SBoudrias I've tracked back https://github.com/yeoman/generator/issues/1098 to this issue. It's reported in a lot of places, node.js included (https://github.com/nodejs/node/issues/21210https://github.com/nodejs/node/issues/21210)

Removing rl.close(); fix the issue, but I don't know the consequences. Maybe make it conditional for non windows.

mshima commented 4 years ago

Found https://github.com/porketta/Inquirer.js/commit/91b4216d67bed610cc941c953a622be79ed34d3d at https://github.com/nodejs/node/issues/21771

Diablohu commented 4 years ago

After this fix, there are more problems

  1. The process that run Inquirer.js will never end, make the program hang until killed manually
  2. The option of type list or checkbox cannot be selected. When input UP or DOWN, option will not be switched, instead the last input value showed up 1
mshima commented 4 years ago

Seems this have to be reverted. @Diablohu what is your environment? Is this a regression?

Diablohu commented 4 years ago

@mshima Windows 10 1909 (18363.476) I tried both in PowerShell and the new Windows Terminal. They have the same problems

7.0.1 is fine 7.0.0 has the hang problem

mshima commented 4 years ago

@Diablohu node 8?

Diablohu commented 4 years ago

I tried on both node 10 and 12. Has the same problem

mshima commented 4 years ago

Created a PR reverting last commit https://github.com/SBoudrias/Inquirer.js/pull/881 and another with skip closing workaround https://github.com/SBoudrias/Inquirer.js/pull/882.

mshima commented 4 years ago

Adding process.stdin.unpipe(this.rl.input); before

this.rl.output.end();
this.rl.pause();
this.rl.close();

fix the hang problem.

But not the list and checkbox problem. That can related to other readline uses: https://github.com/SBoudrias/Inquirer.js/blob/0bc1b011e8441e663e788cba66b71ef40aed5252/packages/core/index.js#L42-L46 https://github.com/SBoudrias/Inquirer.js/blob/0bc1b011e8441e663e788cba66b71ef40aed5252/packages/core/hooks.js#L86-L90

famanoder commented 4 years ago

I use inquirer@7.0.1 then it fixed.

yolilufei commented 2 years ago

i met the same problem, here is my env

then i fixed the problem by revert the version with v7.*

just-maik commented 5 months ago

This Issue still exists for me. Using bun 1.1.3 on powershell Win 11 22H2. Tried via bunx @inquirer/demo@latest.

SBoudrias commented 5 months ago

Hi @just-maik, this is a bug you should report to bun (not here.)