Im new to typescript. Im using a serverless solution from google (google cloud functions) that in the background is running Node.js with typescript. When I get an "runtime error" in the logs I see an error in a .js file, this makes sense since .ts code is compiled to .js but it makes debugging a lot harder as I write typescript code and not javascript code. In general I would like to see the line that produced the error in .ts and not in .js. Is this possible?
2
-
You can have TypeScript create source maps, which can be used to relate the line and column informtaion back to the original TypeScript source. Debuggers can use them automatically, no idea how to integrate them into the logs you're dealing with, though.T.J. Crowder– T.J. Crowder2019-07-06 13:08:03 +00:00Commented Jul 6, 2019 at 13:08
-
Does this answer your question? How to get error information relating to TypeScript file lines number in node.js?cjbarth– cjbarth2020-11-02 14:49:52 +00:00Commented Nov 2, 2020 at 14:49
Add a comment
|
1 Answer
You will need a "source map" to map the JavaScript line numbers to TypeScript line numbers.
You can do this with the source-map-support node module. First install it in your project:
npm install source-map-support
Then add this to your TypeScript file (index.ts):
require('source-map-support').install()
Then, if you function crashes, the line numbers should show TypeScript source lines.
1 Comment
T.J. Crowder
That's really cool. (I kind of missed the fact it was Node.js running the function in the background, but...I didn't know that anyway, so. :-) )