ts-node: Line numbers in error stack not changing

In my code generator project, I watch directory and on each change do require.cache cleaning and rerequire modules from that directory.

And I use stack to implement one important feature.

var stack = new Error().stack;
var stackLines = stack.match(/[^\r\n]+/g);
console.log(stackLines[1]) 

>>>
at Object.<anonymous> (/Workspace/gener/data.js:1:13)

Rerequire works fine, because each time file changes, I see that console.log, meaning file is actually rerequired.

But if I move var stack = new Error().stack; down by 5 lines, I still get:

at Object.<anonymous> (/Workspace/gener/data.js:1:13) // I get
at Object.<anonymous> (/Workspace/gener/data.js:6:13) // I should get

If I do same experiment in pure js and node - it works fine.

So the only moving part between working version and not working version is node server.js and ts-node server.js

About this issue

  • Original URL
  • State: open
  • Created 7 years ago
  • Reactions: 10
  • Comments: 15 (5 by maintainers)

Most upvoted comments

I discovered the culprit! Protractor activates it’s own source-map-support, which probably conflicts with the one in ts-node. Adding a skipSourceMapSupport: true to Protractor’s config resolves the issue completely!

I’ll post an issue at source-map-support to either resolve this issue or log a warning when it’s activated multiple times.

All of a sudden my lines are off on stacktraces again. I am passing the tsconfig.json using --project so sourceMap support is on and I am loading source-map-support anywhere I can see. I am not quite sure how to resolve the offsets?