Ts-node: reported stackframe provide wrong line number (on Windows)

Created on 23 May 2020  路  5Comments  路  Source: TypeStrong/ts-node

Expected Behavior

Expecting ts-node to report accurate stack frame, pointing to the original typescript file.

Steps to reproduce the problem

package.json

{
  "name": "tsnode-issue",
  "version": "1.0.0",
  "main": "index.js",
  "dependencies": {
    "typescript": "^3.9.3"
  }
}

test.ts

/* some comment */
function someFunc() {
    throw new Error("Error");
}
; (() => {
    try {
        /* some comment */
        someFunc();
    }
    catch (err) {
        /* some comment */
        console.log("Error Found", err);
    }
})();

( no tsconfig file necessary)

Minimal reproduction

npx: installed 8 in 2.249s
Error Found Error: Error
    at someFunc (c:\temp\tsnode-issue\test1.ts:3:11)
    at c:\temp\tsnode-issue\test1.ts:9:9
    at Object.<anonymous> (c:\temp\tsnode-issue\test1.ts:15:3)
    at Module._compile (internal/modules/cjs/loader.js:778:30)
    at Module.m._compile (C:\Users\eross\AppData\Roaming\npm-cache\_npx\23236\node_modules\ts-node\src\index.ts:858:23)
    at Module._extensions..js (internal/modules/cjs/loader.js:789:10)
    at Object.require.extensions.(anonymous function) [as .ts] (C:\Users\eross\AppData\Roaming\npm-cache\_npx\23236\node_modules\ts-node\src\index.ts:861:12)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)
npx: installed 8 in 2.184s
Error Found Error: Error
    at someFunc (c:\temp\tsnode-issue\test1.ts:3:11)
    at c:\temp\tsnode-issue\test1.ts:8:9
    at Object.<anonymous> (c:\temp\tsnode-issue\test1.ts:14:3)
    at Module._compile (internal/modules/cjs/loader.js:778:30)
    at Module.m._compile (C:\Users\eross\AppData\Roaming\npm-cache\_npx\17244\node_modules\ts-node\src\index.ts:839:23)
    at Module._extensions..js (internal/modules/cjs/loader.js:789:10)
    at Object.require.extensions.(anonymous function) [as .ts] (C:\Users\eross\AppData\Roaming\npm-cache\_npx\17244\node_modules\ts-node\src\index.ts:842:12)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)
  • spot the that the stack frame is wrong
    at c:\temp\tsnode-issue\test1.ts:9:9 incorrect with [email protected]
    where it should report
    at c:\temp\tsnode-issue\test1.ts:8:9 '(correct with [email protected]

In real production, the line number discrepancy can be large and annoying as it make it almost impossible to identify where the exception was raised ( annoying when doing TDD)


https://github.com/TypeStrong/ts-node-repros/pull/3

Specifications

  • ts-node version: success with 8.9 : failure with 8.10.1 and 8.10.0
  • node version: 10.20.1
  • TypeScript version: 3.9.3
  • tsconfig.json, if you're using one:
{}
  • Operating system and version:
  • If Windows, are you using WSL or WSL2?:
    Bug can be reproduced on Windows from a DOS box,
    cannot exhibit bug in WSL
bug

Most helpful comment

@hbenl @erossignon @rinick
Published 8.10.2 which includes this fix. Thanks for your patience.
Thanks to @jugglingthebits for testing the release.

All 5 comments

Thank you for the detailed report. This may be the same as #1037, which was fixed in #1038 but not yet published. Are you able to test with the latest master code?

npm install 'TypeStrong/ts-node#master'

Thank you for the detailed report. This may be the same as #1037, which was fixed in #1038 but not yet published. Are you able to test with the latest master code?

npm install 'TypeStrong/ts-node#master'

I have a similar issue and the latest code in master branch works

I hope you're going to publish the fix soon since this bug seems to be affecting Mocha Test Explorer (which uses stack traces to detect the test locations in the code).

I should have time to publish a release on Saturday. Unfortunately I am swamped at work this week, so that's the soonest I will be able to work on ts-node stuff.

Maybe @blakeembrey is able to publish a new release in the meantime?

@hbenl @erossignon @rinick
Published 8.10.2 which includes this fix. Thanks for your patience.
Thanks to @jugglingthebits for testing the release.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

watzon picture watzon  路  3Comments

OliverJAsh picture OliverJAsh  路  3Comments

KiaraGrouwstra picture KiaraGrouwstra  路  3Comments

joshua-tj picture joshua-tj  路  3Comments

sodiumjoe picture sodiumjoe  路  4Comments