更新时间:2023-02-02 17:24:20
因此,我通过编译为 es2017
而不是 es6
解决了该问题.
So, I resolved the issue by compiling to es2017
instead of es6
.
我注意到当我将 async
函数传递给 express
路由器时,会发生此问题.但是,返回 Promise
的函数没有问题.
I noticed the issue occurs when i pass async
functions to the express
router. Yet, functions returning a Promise
had no issue.
我发现问题是,当将TypeScript代码编译为 es6
时,它会转换
I found the problem was that when compiled TypeScript code to es6
it converts
async function() {...
到
__awaiter(this, void 0, void 0, function* () {...
这是 Generator
发挥作用的地方.看来 express
在处理请求后无法正确释放它.由于 es2017
支持 async
功能,因此这不再是问题.
This is where Generator
s come in play. It looks like express
cannot correctly free this after handling a request. Since es2017
supports async
function this is not a problem anymore.
另外,我还必须删除软件包 express-validator
,因为他们的验证中间件已编译为相同的 Generator
结构.
Additionally I had to remove the package express-validator
, because their validation middleware was compiled to the same Generator
structure.