node.jsstack-tracerollupjssource-maps

How to output stack traces pointing to the original files instead of the bundled files in a node app?


I have a node app that is bundled with sourcemaps (inline or not makes no difference) using Rollup.

When an error is thrown, I get something like

  Error: FF
      at Function.<anonymous> (/.../dist/media-processing-1nOWWNQS.js:27116:35)
      at step (/.../dist/media-processing-1nOWWNQS.js:161:23)
      at Object.next (/.../dist/media-processing-1nOWWNQS.js:142:53)
      at fulfilled (/.../dist/media-processing-1nOWWNQS.js:132:58)
      at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

How to I get the stack traces to point to the original, unbundled file (e.g. "/.../app/src/helpers/media-processing.ts")?

My sourcemaps are valid because adding breakpoints in VSC works when launching the debug mode.


Solution

  • Apparently, you need to enable source maps with node apps.

    e.g node --enable-source-maps dist/entry-main.js