Skip to content

Commit 5da31e6

Browse files
authored
Add troubleshooting section for testing source maps locally (#869)
1 parent cb87941 commit 5da31e6

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

docs/sourcemaps.rst

+37
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,43 @@ Sentry expects that source code and source maps in a given release are uploaded
359359

360360
If you upload artifacts **after** an error is captured by Sentry, Sentry will not go back and retroactively apply any source annotations to those errors. Only new errors triggered after the artifact was uploaded will be affected.
361361

362+
Verify your source maps work locally
363+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
364+
365+
If you find that Sentry is not mapping filename, line, or column mappings correctly, you should verify that your source maps are functioning locally. To do so, you can use Node.js coupled with Mozilla's `source-map library <https://github.com/mozilla/source-map>`_.
366+
367+
First, install ``source-map`` globally as an npm module:
368+
369+
.. code-block:: bash
370+
371+
npm install -g source-map
372+
373+
Then, write a script that reads your source map file and tests a mapping. Here's an example:
374+
375+
.. code-block:: JavaScript
376+
377+
var fs = require('fs'),
378+
path = require('path'),
379+
sourceMap = require('source-map');
380+
381+
// file output by Webpack, Uglify, etc.
382+
var GENERATED_FILE = path.join('.', 'app.min.js.map');
383+
384+
// line and column located in your generated file (e.g. source of your error
385+
// from your minified file)
386+
var GENERATED_LINE_AND_COLUMN = {line: 1, column: 1000};
387+
388+
var rawSourceMap = fs.readFileSync(GENERATED_FILE).toString();
389+
var smc = new sourceMap.SourceMapConsumer(rawSourceMap);
390+
391+
var pos = smc.originalPositionFor(GENERATED_LINE_AND_COLUMN);
392+
393+
// should see something like:
394+
// { source: 'original.js', line: 57, column: 9, name: 'myfunc' }
395+
console.log(pos);
396+
397+
If you have the same (incorrect) results locally as you do via Sentry, double-check your source map generation configuration.
398+
362399
Verify your source files are not too large
363400
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
364401

0 commit comments

Comments
 (0)