1.安装source-map
npm install source-map
2.在.map 文件同目录下 建 sourceMap.js文件
const sourceMap = require('source-map');
const fs = require('fs');
// read file
const readFile = function (filePath) {
return new Promise(function (resolve, reject) {
fs.readFile(filePath, { encoding: 'utf-8' }, function (error, data) {
if (error) {
console.log(error)
return reject(error);
}
resolve(JSON.parse(data));
});
});
};
// Find location
async function searchSource(filePath, line, column) {
const rawSourceMap = await readFile(filePath)
const consumer = await new sourceMap.SourceMapConsumer(rawSourceMap);
const res = consumer.originalPositionFor({
'line': line,
'column': column
});
consumer.destroy();
console.log(res);
}
searchSource('map文件名', 报错的行数, 报错的列数);
3. node 执行 sourceMap.js文件
1) cd 目录
2) node souceMap.js