Search code examples
javascriptnode.jstypescriptnodemon

Is there source map support for typescript in node / nodemon?


I have a node project written in typescript@2.

My tsconfig has sourceMap set to true and the *.map.js files are generated. When I execute my transpiled *.js JavaScript files via node or nodemon, I only see the error messages relative to the js file and not to the mapped typescript files; I assume it's completely ignored.

Is sourceMap support only intended for browser-support? Or can I use it together with node or nodemon? If the latter, how would I enable it?

I want to see runtime errors detected from an executed javascript file relative to the original typescript file.


Solution

  • The answers here are correct for Node versions before v12.12.0, which added the --enable-source-maps flag (experimental until v15.11.0, v14.18.0). With that enabled, source maps are applied to stack traces without an additional dependency. As demonstrated in this article, it has the slightly different and possibly beneficial behavior of including both the generated .js file location and the source file location. For example:

    Error: not found
        at Object.<anonymous> (/Users/bencoe/oss/source-map-testing/test.js:29:7)
            -> /Users/bencoe/oss/source-map-testing/test.ts:13:7