我正在使用错误边界组件来捕获反应错误,它工作正常。
我的问题是,在生产应用程序中,日志记录有点用处,因为组件堆栈看起来像这样:
\n in t\n in t\n in t\n in t\n in t\n in div\n in t\n in u\n in n\n in t\n in t
在开发环境中,组件堆栈更有用:
in ErrorPage (created by Route)\n in Route (at Routes.js:60)\n in Switch (at Routes.js:46)\n in Router (created by BrowserRouter)\n in BrowserRouter (at Routes.js:45)\n in div (at Routes.js:43)\n in ThemeProvider (at theme.js:1262)\n in Theme (at Routes.js:42)\n in Provider (at Routes.js:41)\n in ErrorBoundary (at Routes.js:40)\n in Routes (at index.js:12)
消息也是如此。在生产中我们得到:
t.value (http://localhost:3333/static/js/main.5a3e606e.js:1:680858
在开发中:
Uncaught TypeError: Person is not a constructor
at ErrorPage._this.click2 (ErrorPage.js:12)
有没有办法让反应错误映射到源代码并使日志记录在生产中实际可用?
更新:我正在使用一个名为http://js.jsnlog.com/的库来处理日志并实际捕获所有内容(甚至是事件处理程序)。这就是边界组件看起来像https://pastebin.com/aBFtD7DB的样子。问题不是捕捉错误,而是在生产中它们是无用的。