Javascript NodeJS/Express中的setTimeout抛出类型错误:无法读取属性';客户';未定义的
我在nodejs有以下基本快速路线:Javascript NodeJS/Express中的setTimeout抛出类型错误:无法读取属性';客户';未定义的,javascript,node.js,express,typeerror,settimeout,Javascript,Node.js,Express,Typeerror,Settimeout,我在nodejs有以下基本快速路线: app.get('/timeout', function (req, res) { setTimeout(() => { console.log('timeout'); }, 2000); res.send({ hello: "world" }); }); 它不起作用,它会抛出一个错误 TypeError:无法读取未定义的属性“client” 在setTimeout(/Users/mypr
app.get('/timeout', function (req, res) {
setTimeout(() => {
console.log('timeout');
}, 2000);
res.send({ hello: "world" });
});
它不起作用,它会抛出一个错误
TypeError:无法读取未定义的属性“client”
在setTimeout(/Users/myproject/node_modules/@sendgrid/mail/src/classes/mail service.js:58:10)
at/Users/myproject/router.js:87:7
我不明白为什么?我尝试过不执行控制台.log
,尝试了箭头函数、异步等待、不发送res.send
。这里的客户是什么意思
另一件让我困惑的事情是,错误的第一行提到了sendgrid模块——我确实安装了它,但我根本没有使用它——setTimeout(/Users/myproject/node_modules/@sendgrid/mail/src/classes/mail service.js:58:10)我很抱歉,我发现了错误!我的VS代码自动从sendgrid导入了setTimeout函数。这不是标准的setTimeout函数,因此引发了一个错误。没有看到它自动导入了这个
const { setTimeout } = require('@sendgrid/mail');
很抱歉,我发现了错误!我的VS代码自动从sendgrid导入了setTimeout函数。这不是标准的setTimeout函数,因此引发了一个错误。没有看到它自动导入了这个
const { setTimeout } = require('@sendgrid/mail');