To begin collecting source-maps, node must be run with --enable-source-maps
(or with NODE_V8_COVERAGE
set).
At which point, the new built-in module source_map
can be used to interact with the source-map cache:
// tooling has one interface into the source-map cache, URIs, any type of module that we
// wish to attach source-maps to (ESM, CJS, evals, data-urls) needs to have a methodlogy
// for setting a URI; Two different source-maps cannot be stored at the same URI.
const {cache} = require('source_map');
const sm1 = cache.sourceMapFromURI(`file://${require.resolve('./my-module')}`);
These methods return the same data-structure that is written to disk when
executing with NODE_V8_COVERAGE
:
{
"url": "data:abc123", // original source-map URL.
"data": {} // parsed source-map or null.
}
When executing with --enable-source-maps
, stack traces will be rewritten if source-maps are found corresponding
to files represented in the stack-trace.
The hope is to intitially engage folks rom the https://github.com/evanw/node-source-map-support project, to support stack-trace rewritting in Node.js. And, in the future, work with the V8 team to move more of this behavior into V8 itself.
This is fantastic and a real pain for a lot of Node.js developers - thank you for working on it.
Making source maps work out of the box in stack traces would be great and it's mostly blocked on someone actually doing the work on making it happen.