执行下列代码从map文件解析出源码位置
var sourceMap = require("source-map");
var fs = require("fs");
// 此处替换为你下载下来的 sourcemap 文件
let data = fs.readFileSync("../index.js.5d59fc.js.map").toString();
const consumer = new sourceMap.SourceMapConsumer(data);
consumer.then(c => {
// 此处替换为原始报错的行列号
const line = 23,
column = 112003;
let s = c.originalPositionFor({ line, column });
console.log(s);
console.log(`origin code for line: ${line}, ${column}\n`);
console.log(
`======================================================================`
);
console.log(
c
.sourceContentFor(s.source)
.split("\n")
.slice(Math.max(s.line - 10, 0), s.line + 10)
.join(`\n`)
);
console.log(
`======================================================================`
);
});
vue中
window.οnerrοr=()=>{}
和
window.addEventListener(‘error’,()=>{})
在打包后会失效
可以使用
app.config.errorHandler = function (err, vm, info) {
console.log('vue捕获er', JSON.stringify(err));
console.log('vue捕vm获', vm);
console.log('vue捕获info', info);
console.log('--err-', ErrorStackParser.parse(err as any));
throw err;
};