我希望对Error.stack
做进一步的处理(其实就是不显示name
和message
那一行), 但是只要一处理, 就不能映射到sourceMap
了, 代码和打印结果如下, can you help help me?
const { stack } = new Error("")
if (stack) {
console.log(stack)
console.log(stack.split("\n").splice(1).join("\n"))
}
// 这是 console.log(stack)
// sourceMap 正确
Error
at log (index.ts:7)
at withinRect (index.tsx:39)
at index.tsx:202
at updateMemo (react-dom.development.js:16835)
at Object.useMemo (react-dom.development.js:17315)
at useMemo (react.development.js:1643)
at App (index.tsx:202)
at renderWithHooks (react-dom.development.js:16241)
at updateFunctionComponent (react-dom.development.js:18328)
at beginWork$1 (react-dom.development.js:20151)
// 这是 console.log(stack.split("\n").splice(1).join("\n"))
// sourceMap 错误
at log ( http://192.168.3.7:8080/static/scripts/index.e7695f.js?e7695f02d813f4d2c31a:66434:17)
at withinRect ( http://192.168.3.7:8080/static/scripts/index.e7695f.js?e7695f02d813f4d2c31a:65917:59)
at http://192.168.3.7:8080/static/scripts/index.e7695f.js?e7695f02d813f4d2c31a:66044:96
at updateMemo ( http://192.168.3.7:8080/static/scripts/index.e7695f.js?e7695f02d813f4d2c31a:41208:19)
at Object.useMemo ( http://192.168.3.7:8080/static/scripts/index.e7695f.js?e7695f02d813f4d2c31a:41688:16)
at useMemo ( http://192.168.3.7:8080/static/scripts/index.e7695f.js?e7695f02d813f4d2c31a:54182:21)
at App ( http://192.168.3.7:8080/static/scripts/index.e7695f.js?e7695f02d813f4d2c31a:66044:74)
at renderWithHooks ( http://192.168.3.7:8080/static/scripts/index.e7695f.js?e7695f02d813f4d2c31a:40614:18)
at updateFunctionComponent ( http://192.168.3.7:8080/static/scripts/index.e7695f.js?e7695f02d813f4d2c31a:42701:20)
at beginWork$1 ( http://192.168.3.7:8080/static/scripts/index.e7695f.js?e7695f02d813f4d2c31a:44524:16)
这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。
V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。
V2EX is a community of developers, designers and creative people.