Ts-node: no stack trace for runtime errors

Created on 20 May 2018  路  6Comments  路  Source: TypeStrong/ts-node

I have this file a.ts:

throw new Error('my uber error')

when I run npx node-ts a.ts I get the following output:

capaj@capaj-i7-4771:~/git_projects/tests/type-gql$ npx ts-node sample-query.ts
my uber error

I run this with typescript 2.8.3, sourceMap enabled, node 10.1.0

Interesting thing-when I run it with ts-node-dev I indeed get the stack trace as expected:

capaj@capaj-i7-4771:~/git_projects/tests/type-gql$ npx ts-node-dev sample-query.ts
Error: my uber error
    at Object.<anonymous> (/home/capaj/git_projects/tests/type-gql/a.ts:1:7)
    at Module._compile (internal/modules/cjs/loader.js:678:30)
    at Module.m._compile (/tmp/ts-node-dev-hook-23796247946240978.js:44:25)
    at Module._extensions..js (internal/modules/cjs/loader.js:689:10)
    at require.extensions.(anonymous function) (/tmp/ts-node-dev-hook-23796247946240978.js:46:14)
    at Object.nodeDevHook [as .ts] (/home/capaj/git_projects/tests/type-gql/node_modules/ts-node-dev/lib/hook.js:61:7)
    at Module.load (internal/modules/cjs/loader.js:589:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:528:12)
    at Function.Module._load (internal/modules/cjs/loader.js:520:3)
    at Module.require (internal/modules/cjs/loader.js:626:17)
[ERROR] 11:40:41 Error: my uber error

Most helpful comment

If I do npx -s sh ts-node a.ts it works again, it really just looks like it's related to npx and how it's handling node.js scripts. Going to close this, feel free to open it with npx instead.

All 6 comments

Appears to work for me. Please make sure you've narrowed down the issue to something that can be reproduced. Is it possible you have an old dependency in the dependency tree (e.g. https://github.com/evanw/node-source-map-support/pull/212)?

image

Interestingly, I just tried with npx and see the same issue so this does not look related to ts-node.

If I do npx -s sh ts-node a.ts it works again, it really just looks like it's related to npx and how it's handling node.js scripts. Going to close this, feel free to open it with npx instead.

Possibly related to this line which prints only the message on failure: https://github.com/zkat/npx/blob/b7c8b9f07605b9f41931ad3ef8e74a65d2f062bb/index.js#L113

And https://github.com/zkat/npx/blob/b7c8b9f07605b9f41931ad3ef8e74a65d2f062bb/index.js#L258-L268 which confirms the suspicion - it just runs node.js scripts directly to avoid spawning another shell but I suspect ts-node-dev is spawning the shell itself somewhere.

Will reopen in npx repo, thanks.

Was this page helpful?
0 / 5 - 0 ratings