Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

sourcemap-view

vilien15MIT1.0.11TypeScript support: included

View the original code from the sourcemap based on the error lineno and colno.

sourcemap, sourcemap view, js error, original code

readme

sourcemap-view

View the original code from the sourcemap based on the error lineno and colno.

Installation

npm install sourcemap-view

Why would you want to do that?

When js throws an exception, we can view the original code without Chrome Console or Other.

Uncaught TypeError: Cannot read property 'a' of undefined
    at a.getSameError (app.07cd8612.js:1:3842)
    at app.07cd8612.js:1:3357

Usage

const fs = require('fs');
const sourcemapView = require('sourcemap-view');

const sourcemapRaw = fs.readFileSync('./app.07cd8612.js.map', { encoding: 'utf-8'});

const view = sourcemapView(JSON.parse(sourcemapRaw));

view(1, 3842); // { file: './HelloWorld.js', lineNo: 43, colNo: 29, name: 'a', content: <Original Code> }
view(1, 3357); // { file: './HelloWorld.js', lineNo: 35, colNo: 0, name: 'setTimeout', content: <Original Code> }

License

MIT.