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

k0pernikus picture k0pernikus · Feb 7, 2017 · Viewed 19.4k times · Source

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.

Answer

Stephen Paul picture Stephen Paul · May 16, 2017

I recently got this working in my express app. Steps as follows:

Install the required library:

npm install --save-dev source-map-support

In your entry point (eg app.ts):

require('source-map-support').install();

In your app.ts, you may also require better logging for errors within promises:

process.on('unhandledRejection', console.log);

In your tsconfig, under compilerOptions:

"inlineSourceMap": true