我在 index.ts 中调用 time-helper.ts 中的 waitForFn(),出错的调用栈是这样的:
Error: xx
at /src/helpers/time-helper.ts:15:9
at Generator.next ()
at fulfilled (/src/helpers/time-helper.ts:5:58)
这个调用栈有啥问题呢?只显示出了 time-helper 模块的文件信息,完全不显示调用者的信息,这样一来,完全不知道是谁调用了这个 waitForFn() 函数。你从错误信息里都不知道是哪个函数出错了。
出现这种情况,原因在这里:「链接」
解决办法在这里:「链接」
简单总结下,就是:
在异步函数返回之前,系统会清空当前调用线,然后把异步函数中的调用栈写进去。
解决办法:只要把 tsconfig.json 文件中的 compilerOptions.target 改成 es2018 或以上的版本即可。
改完后效果:
Error: xx
at waitForFn (/src/helpers/time-helper.ts:15:9)
at Paraswap.run (/src/commands/paraswap.ts:70:5)
at Command. (/src/index.ts:26:7)
at Command.parseAsync (/node_modules/commander/lib/command.js:904:5)
at /src/index.ts:30:5
可见整个调用栈都非常清晰。
页面更新:2024-05-14
本站资料均由网友自行发布提供,仅用于学习交流。如有版权问题,请与我联系,QQ:4156828
© CopyRight 2020-2024 All Rights Reserved. Powered By 71396.com 闽ICP备11008920号-4
闽公网安备35020302034903号