0

I have the following basic express route in nodejs:

app.get('/timeout', function (req, res) {
    setTimeout(() => {
      console.log('timeout');
    }, 2000);

    res.send({ hello: "world" });
  });

It doesn't work, it throws an error

TypeError: Cannot read property 'client' of undefined at setTimeout (/Users/myproject/node_modules/@sendgrid/mail/src/classes/mail-service.js:58:10) at /Users/myproject/router.js:87:7

I don't understand why? I have tried not doing a console.log, I tried arrow functions, async await, not sending res.send. What client is meant here?

The other thing that confuses me is that the first line of the error mentions a sendgrid module -which I do have installed, but which I'm not using in this route at all- : at setTimeout (/Users/myproject/node_modules/@sendgrid/mail/src/classes/mail-service.js:58:10)

1 Answer 1

2

I'm so sorry, I found the error! My VS-Code auto-imported a setTimeout function from sendgrid. This is not the standard setTimeout function, so it threw an error. Didn't see it imported this automatically.

const { setTimeout } = require('@sendgrid/mail');
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.