The issue with stack traces is described perfectly here nodejs/node#11865 (comment).
One way to solve this is to use ndb. Steps to solve:
- Move the script you're testing to an npm script (so it can be run
npm run my-script
). This helps ndb to discover the script. - Go to your project directory root and run
npm i -g ndb && ndb
. Debugger window should open up - From top-right icons, click the one which says "Pause on exceptions"
- Then run your
my-script
from bottom-left in the window - When the exception is thrown, you'll be able to see the whole stack trace under "Call stack" in the right column.