You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

React Native开发模式下如何阻止Sentry发送JS及原生端错误事件?

如何避免开发期间将JS和原生端错误发送至Sentry?

开发模式下的JS错误

开发模式JS错误示例1
开发模式JS错误示例2

开发模式下的原生崩溃错误

开发模式原生崩溃错误示例

针对Sentry @sentry/react-native 6.1.0版本尝试过但无效的方案:

方案1:

Sentry.init({
  enabled: !__DEV__,
  dsn: "SOME_VALID_URL"
})

结果:该方案仅对JS错误有效,但仍会向Sentry发送原生错误

方案2:

if(!__DEV__) {
  Sentry.init({
    dsn: "SOME_VALID_URL"
  })
}

结果:在根组件中使用Sentry.wrap时会生成如下警告:

App Start Span could not be finished. Sentry.wrap was called before Sentry.init.

对应的代码示例:

if(!__DEV__) {
  Sentry.init({
    dsn: "SOME_VALID_URL"
  })
}

function RootLayout() {
 ...
}

export default Sentry.wrap(RootLayout);

内容的提问来源于stack exchange,提问作者Roni Castro

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.16 12:45:15