Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

162
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!