zkat / npx

execute npm package binaries (moved)

Home Page:https://github.com/npm/npx

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Print node.js script stack traces like regular node

blakeembrey opened this issue · 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 TypeStrong/ts-node#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.

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?

npx/index.js

Line 113 in b7c8b9f

!argv.q && console.error(err.message)