Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

158
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda