16

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

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

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?

3
  • Typescript developers must suffer with You should be able to see typescript files in debugger,. If say in Chrome do you see it try and load any .map files?. Does the generated javascript file have any references to .map files. I've not used Webstorm for a while now, but maybe it keeps internal map files when running in the debugger, so maybe you need to make sure the TypeScript config has map files enabled.
    – Keith
    Commented Oct 21, 2016 at 10:04
  • Thanks, I should have mentioned this is for server dev, not browser. The runtime stack trace of course is when the app is run, not while being debugged.
    – Jackpile
    Commented Oct 21, 2016 at 10:17
  • Oh, ok. I'm not sure node.js has source map support built in. But I've just seen -> github.com/dmail-old/node-sourcemap and others..
    – Keith
    Commented Oct 21, 2016 at 10:21

1 Answer 1

29

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

Another approach is using the ts-node package

5
  • I put in a Webstorm issue with the hopes they build this into Webstorm with a simple checkbox to enable. youtrack.jetbrains.com/issue/WEB-44801
    – Inigo
    Commented Apr 9, 2020 at 4:58
  • @burt-harris Webstorm is a Jetbrains product, re: the question being answered. It would be nice if Jetbrains built this into their IDE as they do so many other things, as explained in the opened issue. I referenced your comment.
    – Inigo
    Commented Apr 10, 2020 at 2:18
  • The answer I provided should be workable independent of IDE. I can't help with Webstorm specifically. I use vscode. Commented Apr 12, 2020 at 23:37
  • This works great for webstorm. Install the library globally and add -r source-map-support/register in the node parameters field of launch configuration.
    – metasync
    Commented Apr 14, 2020 at 5:08
  • This just works with a minimal of fuss. Within 30s i've installed source-map-support, added it my start script for TS e.g. node -r source-map-support/register build and I can see .ts stack traces.... beautiful Commented Mar 1, 2021 at 23:59

Not the answer you're looking for? Browse other questions tagged or ask your own question.