Inquirer.js icon indicating copy to clipboard operation
Inquirer.js copied to clipboard

Multiple Questions on Windows 10 Hangs

Open jlkalberer opened this issue 6 years ago • 13 comments

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.

jlkalberer avatar Jan 19 '19 16:01 jlkalberer

@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 avatar Jan 04 '20 16:01 mshima

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

mshima avatar Jan 04 '20 17:01 mshima

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

Diablohu avatar Jan 06 '20 11:01 Diablohu

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

mshima avatar Jan 06 '20 12:01 mshima

@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

Diablohu avatar Jan 06 '20 12:01 Diablohu

@Diablohu node 8?

mshima avatar Jan 06 '20 12:01 mshima

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

Diablohu avatar Jan 06 '20 13:01 Diablohu

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 avatar Jan 06 '20 14:01 mshima

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

mshima avatar Jan 06 '20 14:01 mshima

I use [email protected] then it fixed.

famanoder avatar Jan 13 '20 10:01 famanoder

i met the same problem, here is my env

  • os macOs 11.5.1
  • shell zsh
  • node v14.*
  • inquirer v8.*

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

yolilufei avatar Dec 24 '21 06:12 yolilufei

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

just-maik avatar Apr 12 '24 07:04 just-maik