Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

163
Visualizações
Setting inquirer prompt array in a loop breaks prompt

How can I build an inquirer prompt array dynamically? i.e. when I'm iterating through items to dynamically add prompt elements.

When I try, the program does not wait for a response. It continues with the rest of the code and exits.

Note: I am using async/await in this example but removing it does not change anything

Working example As a baseline to confirm everything I'm not showing is setup correctly, this code works. The elements are not created in a loop and program waits for user input as expected.

...
const iqElements = [{
    type: 'input',
    name: 'gitref',
    message: 'Git reference:',
    default: 'master',
  }]
const iq = await inquirer.prompt(iqElements)

Problem Example: This is the problem. When I build the iqElements array in a for loop, the program does not wait for user input. It continues and exits.

The element name is contrived for this simplified example. My actual code sets the name value from unique properties on the elements I'm iterating over.

...
const iqElements = []
for (let i = 0; i < 2; i++) {
  iqElements.push({
    type: 'input',
    name: 'gitref'+i,
    message: 'Git reference:',
    default: 'master',
  })
}
// Confirmed the elements are build before the next line is called
console.log(iqElements)
const iq = await inquirer.prompt(iqElements)
about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda