Promise.all bringing up "TypeError: undefined is not iterable (cannot read property Symbol(Symbol.iterator))"

Viewed 6929

I've been working on a React webapp to send bulk SMS messages. The basic summary: you upload a CSV file, it pulls phone numbers from it and maps them, and then you can send a text to the phone numbers using Twilio. The last time I tested it, everything worked fine.

For various reasons I haven't touched that part of the app for a while. After looking through my phone, the last time I actually tested the SMS feature would have been May 26. When I tested it today, I got this error message in the terminal:

TypeError: undefined is not iterable (cannot read property Symbol(Symbol.iterator))

at Function.all ()

at /Users/[me]/furlane_tool/client/server/index.js:30:11

The line in question is a Promise.all line. I opened an older version from June (oldest version I can access), and I had to do some updates to node to get some stuff working (namely eslint). It still brought up the error. When I changed the line to a lower-case "promise" as a test, I got "ReferenceError: promise is not defined".

I'm wondering if there was some change to Node or React and how they handle promises since then, or if I screwed up the code somehow while trying to get some other unrelated features working. It DOES properly map the numbers in the terminal.

Relevant code:

app.post('/test', (req, res) => {
  res.header('Content-Type', 'application/json');
  const numbers = req.body.to;
    console.log("This is the to numbers:" + numbers);


  Promise.all(
    console.log(numbers[0]),
    numbers[0].map(number => {
      console.log("Numbers mapped:", number);
      return client.messages.create({
        to: number,
        from: process.env.TWILIO_PHONE_NUMBER,
        body: req.body.body
      });
    })
  )
    .then(messages => {
      console.log('Messages sent!');
    })
    .catch(err => console.error(err));
});

Let me know if you need any other parts of the code!

1 Answers

Promise.all() should take an array argument

Related