如何使用Node从WebStorm中的JavaScript stacktrace导航到原始TypeScript文件? [英] How do I navigate to original TypeScript file from JavaScript stacktrace in WebStorm with Node?

查看:95
本文介绍了如何使用Node从WebStorm中的JavaScript stacktrace导航到原始TypeScript文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是TypeScript的新手。在Mac上,我将WebStorm 2016.2.4用于带有TypeScript 2.0的Node。

I'm new to TypeScript. On a Mac I'm using WebStorm 2016.2.4 for Node with TypeScript 2.0.

使用生成的映射,交互式调试可以正常工作,但是运行时堆栈跟踪链接指向JavaScript文件,不是原始的TypeScript文件。

Interactive debugging works fine using generated maps, but runtime stack trace links point to JavaScript files, not original TypeScript files.

这是正常现象吗?是否缺少我可以将这些链接转换为原始TypeScript文件和行的WebStorm功能,或者这仅仅是TypeScript开发人员必须遭受的痛苦?

Is this normal and expected? Is there a WebStorm feature I'm missing that can translate those links to the original TypeScript file and line or is this just something TypeScript developers must suffer with?

推荐答案

我通过使用模块 源地图支持/注册 。这可以通过多种方式来完成,例如在的节点命令行上-要求source-map-support / register ,或者您可以在主程序中要求它。对于单元测试,我将其保存在 mocha.opts 文件中:

I get stack traces using the TypeScript source file line numbers by requiring module source-map-support/register. This can be done a number of ways, e,.g. on the node command line with --require source-map-support/register, or you can require it in your main program. For unit testing, I have it in my mocha.opts file:

--require source-map-support/register
--recursive

另一种方法是使用 ts-node

Another approach is using the ts-node package

这篇关于如何使用Node从WebStorm中的JavaScript stacktrace导航到原始TypeScript文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆