React Sentry TypeError:无法读取未定义的属性(Reading' ComponentStack')

发布于 2025-02-05 18:54:43 字数 1367 浏览 3 评论 0 原文

我正在尝试在我的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
enter image description here

ErrorBoundry component removed
enter image description here

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>
  )
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

十年九夏 2025-02-12 18:54:43

我通过从CRA 4升级到5。也许这对别人有帮助。

I resolved this by upgrading from CRA 4 to 5. e.g. react-scripts. Maybe this helps someone else.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文