npx icon indicating copy to clipboard operation
npx copied to clipboard

Print node.js script stack traces like regular node

Open blakeembrey opened this issue 7 years ago • 1 comments

Currently when a node.js script throws an error it is caught in the promise and proceeds through the program until console.error(error.message). This results in unexpected behaviour for users who want the regular stack trace like node.js. This issue comes from investigation into https://github.com/TypeStrong/ts-node/issues/592 (e.g. npx ts-node a.ts does not print anything useful).

A possible workaround could be to console.error(error) which would show the stack (haven't checked how node.js does this internally) and sub-class existing errors in the script so you can switch the behaviour based on where it originated. Or wrapping Module.runMain() in a try..catch and doing something with the error there.

blakeembrey avatar May 20 '18 10:05 blakeembrey

Experiencing issues like this as well, it would be really useful to show the error in all of its nasty glory, instead of just the message.

Is there any reason npx uses console.error(err.message) instead of console.error(err) here? https://github.com/zkat/npx/blob/b7c8b9f07605b9f41931ad3ef8e74a65d2f062bb/index.js#L113

ferm10n avatar Jul 30 '18 15:07 ferm10n