我正在尝试在我的React项目中使用Sentry的 errorboundry
组件,以便我可以包含有关我的React应用程序报告的错误,因为它在许多不同的网站上都存在,我不想在每个网页和网站上获取所有JS错误。
但是,从我的React应用程序中冒出 errorboundry
的每个错误都会产生一个非常晦涩难懂的错误,例如 typeError:无法读取未定义的属性(读取'componentStack')
>
实际错误没有 errorBoundry
组件应为 typeerror:无法读取未定义的属性(读取'0')
似乎看起来像 componentStack
根据这两个图像分别使用 errorboundy
分别禁用和启用了这两个图像,并防止了任何有用的报告。这些图像取自我的开发环境,我是Craco版本。
eRrorboundry组件添加了

errorboundry组件已删除
代码参考。
ReactDOM.render(
<Sentry.ErrorBoundary fallback={<ErrorFallback />}>
<ApolloProvider client={client}>
<App shop={shop} customiserId={customiserId} />
</ApolloProvider>
</Sentry.ErrorBoundary>,
customiser
);
带有看起来像的后备组件
const ErrorFallback = () => {
return (
<div>An error has occurred</div>
)
}
I am trying to use the ErrorBoundry
component of Sentry in my react project so that I can contain the errors reported to sentry just for my React app as it lives on many different websites and I don't want to pick up every JS error on every web page and website.
However, every error that is bubbling up from my react app into the ErrorBoundry
produces a very obscure and uninformative error such as TypeError: Cannot read properties of undefined (reading 'componentStack')
The actual error without the ErrorBoundry
component should be TypeError: Cannot read properties of undefined (reading '0')
It seems like the componentStack
is overriding and preventing any useful reporting as per these two images with the ErrorBoundy
disabled and enabled respectively. These images are taken from my dev environment and I am the CRACO version.
ErrorBoundry component added

ErrorBoundry component removed

Code references.
ReactDOM.render(
<Sentry.ErrorBoundary fallback={<ErrorFallback />}>
<ApolloProvider client={client}>
<App shop={shop} customiserId={customiserId} />
</ApolloProvider>
</Sentry.ErrorBoundary>,
customiser
);
with a fallback component that looks like
const ErrorFallback = () => {
return (
<div>An error has occurred</div>
)
}
发布评论
评论(1)
我通过从CRA 4升级到5。也许这对别人有帮助。
I resolved this by upgrading from CRA 4 to 5. e.g.
react-scripts
. Maybe this helps someone else.