我在NodeJS中有以下基本的快速路线:
app.get('/timeout', function (req, res) {
setTimeout(() => {
console.log('timeout');
}, 2000);
res.send({ hello: "world" });
});
它不工作,它会抛出一个错误
TypeError:无法在/users/myproject/router.js:87:7的setTimeout(/users/myproject/node_modules/@sendgrid/mail/src/classes/mail-service.js:58:10)读取未定义的属性“client'”
我不明白为什么?我试过不做
另一个让我感到困惑的地方是,错误的第一行提到了一个sendgrid模块--我确实安装了这个模块,但在此路由中根本不使用这个模块:
很抱歉,我发现了错误!我的VS-Code从SendGrid自动导入了一个setTimeout函数。这不是标准的setTimeout函数,因此引发了一个错误。没看到它自动导入了这个。
const { setTimeout } = require('@sendgrid/mail');