Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

prompt blocks the terminal when use in promise chain #811

Closed
ccamensuli opened this issue Jun 20, 2019 · 9 comments · Fixed by #813
Closed

prompt blocks the terminal when use in promise chain #811

ccamensuli opened this issue Jun 20, 2019 · 9 comments · Fixed by #813

Comments

@ccamensuli
Copy link

in this new version 6.4.0
node v12.4.0

when i use in promise chain the second call to prompt method block the terminal

test.js

#!/usr/bin/env node

const inquirer = require("inquirer");

const prompt = inquirer.createPromptModule();

prompt(questions)
.then((answers) => {
console.log('\nOrder receipt:');
return JSON.stringify(answers);
})
.then((lastresponse) => {
return prompt(questions)
.then(function(answers) {
console.log('\nOrder receipt 2:');
console.log(lastresponse);
console.log(JSON.stringify(answers, null, ' '));
return answers;
});
})
.catch(e => {
console.error(e);
});

const questions = [{
type: 'confirm',
name: 'toBeDelivered',
message: 'Is this for delivery?',
default: false
}, {
type: 'input',
name: 'phone',
message: 'What's your phone number?',
validate: function(value) {
var pass = value.match(/^([01]{1})?[-.\s]?(?(\d{3}))?[-.\s]?(\d{3})[-.\s]?(\d{4})\s?((?:#|ext.?\s?|x.?\s?){1}(?:\d+)?)?$/i);
if (pass) {
return true;
}
return 'Please enter a valid phone number';
}
}, {
type: 'list',
name: 'size',
message: 'What size do you need?',
choices: ['Large', 'Medium', 'Small'],
filter: function(val) {
return val.toLowerCase();
}
}, {
type: 'input',
name: 'quantity',
message: 'How many do you need?',
validate: function(value) {
var valid = !isNaN(parseFloat(value));
return valid || 'Please enter a number';
},
filter: Number
}, {
type: 'expand',
name: 'toppings',
message: 'What about the toppings?',
choices: [{
key: 'p',
name: 'Pepperoni and cheese',
value: 'PepperoniCheese'
}, {
key: 'a',
name: 'All dressed',
value: 'alldressed'
}, {
key: 'w',
name: 'Hawaiian',
value: 'hawaiian'
}
]
}, {
type: 'rawlist',
name: 'beverage',
message: 'You also get a free 2L beverage',
choices: ['Pepsi', '7up', 'Coke']
}, {
type: 'input',
name: 'comments',
message: 'Any comments on your purchase experience?',
default: 'Nope, all good!'
}, {
type: 'list',
name: 'prize',
message: 'For leaving a comment, you get a freebie',
choices: ['cake', 'fries'],
when: function(answers) {
return answers.comments !== 'Nope, all good!';
}
}
];

@rspieker
Copy link

I ran into the same issue. The easier step to reproduce is basically to invoke inquirer.prompt multiple times.

const inquirer = require("inquirer");

Promise.resolve()
  .then(() =>
    inquirer.prompt({ type: "confirm", name: "thing", message: "Do the thing", default: true })
  )
  .then(() =>
    inquirer.prompt({ type: "input", name: "sure", message: "Are you sure" })
  );

This will present you with two prompts, whereas the second one does not allow input (and appears to trap CTRL+C too)

Tested on node v8.16.0 and v10.15.3

@hoang-innomize
Copy link

hoang-innomize commented Jun 20, 2019

Me too. We use this as a dependency of pm2-windows-service

npm install @innomizetech/pm2-windows-service
image

We cannot type anything and also CTRL+C also not working.

@danielo515
Copy link

Yep the same is happening to me, only on the latest version.
Not sure what to do.

@hoang-innomize
Copy link

It seems working with v6.3.1, maybe windows updates cause this issue.

@rspieker
Copy link

Until this is fixed, one way to fix it is to make sure inquirer is bound to 6.3.x

I recon for most people this comes down to changing the dependency in package.json

from

"inquirer": "^6.3.1"

to

"inquirer": "~6.3.1"

(^ means the package will use the latest patch AND feature (minor) version, ~ means it will use the latest patch version and does not move over to a newer feature (minor) version)

@haoqunjiang
Copy link

Caused by this commit: #808

slhck added a commit to slhck/vue-cli that referenced this issue Jun 20, 2019
This should revert the upstream bug identified here: SBoudrias/Inquirer.js#811
ryaninvents added a commit to ryaninvents/generator-new that referenced this issue Jun 20, 2019
@chrisdothtml
Copy link
Contributor

PR here: #813

@hongxuWei
Copy link

It seems working with v6.3.1, maybe windows updates cause this issue.

No, I can't work it at 6.3.1 on MacOS

hongxuWei pushed a commit to hongxuWei/awesome-work-flow that referenced this issue Jun 21, 2019
Prompt blocks the terminal when use in promise chain
SBoudrias/Inquirer.js#811
@SBoudrias
Copy link
Owner

I just released 6.4.1 with the event listeners revert.

Thanks all for your patience.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants