Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get error information relating to TypeScript file lines number in node.js?

I am using TypeScript for my node.js backend development. Whenever I get an error in node.js it shows me the line number relating to the transpiled JavaScript (.js) files, not the TypeScript (.ts) files.

If you have used ionic, we get the error corresponding to the typescript file there.

Is there any way I get error line number relating to my typescript file? If yes please explain how and what changes I need to do to the config file.

like image 978
Deepak Poojari Avatar asked May 16 '18 06:05

Deepak Poojari


People also ask

Can you run ts files with node?

It is a superset of JavaScript. In order to execute or run any typescript file, first you need to install node and using it install typescript globally in your local system. Procedure 1: This typescript file greet. ts will create a javascript file at runtime with the same name.

What are ts files JavaScript?

TypeScript is a typed superset of JavaScript that compiles to plain JavaScript. It offers classes, modules, and interfaces to help you build robust components.


1 Answers

Install source-map-support package.

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

Add this line in the entry point of node.js

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

In your tsconfig.json,

{
   "compilerOptions": {
      "sourceMap": true
   }
}

Ref: https://github.com/evanw/node-source-map-support#typescript-demo

like image 194
Ritwick Dey Avatar answered Oct 22 '22 12:10

Ritwick Dey