javascript - NodeJS / Express中的setTimeout抛出TypeError:无法读取未定义的属性'client'
问题描述
我在nodejs中有以下基本快递路线:
app.get('/timeout', function (req, res) {
setTimeout(() => {
console.log('timeout');
}, 2000);
res.send({ hello: "world" });
});
它不起作用,它会引发错误
类型错误:无法在 /Users/myproject/router.js:87 处读取 setTimeout (/Users/myproject/node_modules/@sendgrid/mail/src/classes/mail-service.js:58:10) 处未定义的属性“客户端” :7
我不明白为什么?我试过不做console.log
,我试过箭头功能,异步等待,不发送res.send
。这里的客户是什么意思?
让我感到困惑的另一件事是,错误的第一行提到了一个 sendgrid 模块——我确实安装了它,但我根本没有在这条路线中使用它——:at setTimeout (/Users/myproject/node_modules/@sendgrid/mail/src/classes/mail-service.js:58:10)
解决方案
很抱歉,我发现了错误!我的 VS-Code从 sendgrid自动导入了一个 setTimeout 函数。这不是标准的 setTimeout 函数,所以它抛出了一个错误。没有看到它自动导入这个。
const { setTimeout } = require('@sendgrid/mail');
推荐阅读
- ios - 找不到 iOS 模拟器
- query-optimization - pg-promise的事务序列API中是否保留了顺序?
- c++ - 使用 Stream Builder 查询字符串
- javascript - 无法使用 jQuery get 检索 json 数据
- php - 我用于比较日期的 PHP 脚本无法正常工作
- php - 为什么不能在 laravel 中工作 ajax 上传文件
- python - 在 Docker 容器中运行 python 脚本错误的时区
- haskell - Haskell 中的类型类和类型推断
- mysql - 如何对 MySQL 进行求和和分组?
- database - 我无法在视图中显示我获取的数据