I am developing a Nest.js server and would like to be able to print useful stack trace in console (e.g. console.log). By default, it returns a reference to the line number in the compiled sources (.js). This is not useful for debugging as it's missing the reference to the line number in the original source files (.ts)
Here is my tsconfig.json
{ "compilerOptions": { "module": "commonjs", "declaration": true, "removeComments": true, "emitDecoratorMetadata": true, "experimentalDecorators": true, "target": "es2017", "sourceMap": true, "outDir": "./dist", "_baseUrl": "./", "incremental": true }, "exclude": ["node_modules", "dist"] }
The .map files are generated in the dist folder as well, though it seems to be of no use when checking stack traces in the console.
For visibility purposes: adding the source-map-support NPM package allows for tracing typescript files in the stack trace.
It can be added on the command line with node -r source-map-support/register fileToRun.js
or programatically with
import * as sourceMapSupport from 'source-map-support'; sourceMapSupport.install();
OR
import { install } from 'source-map-support'; install();
OR with ES6 modules
import 'source-map-support/register';
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With