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

Expo SDK 52升级后@sentry/react-native/expo插件解析失败求助

Expo SDK 52升级后@Sentry/react-native/expo插件解析失败问题解决

问题描述

项目从Expo SDK 51升级至SDK 52后,出现错误:

PluginError: Failed to resolve plugin for module "@sentry/react-native/expo" relative to "root to project"

保留@sentry/react-native/expo插件时,Sentry无法正常初始化;移除该插件后,其他Expo插件均可正常运行。

相关配置

app.config.js(移除@sentry/react-native/expo可正常运行)

plugins: [
    [
      '@sentry/react-native/expo',
    ],
    'expo-localization',
    [
      'expo-updates',
    ],
    [
      'expo-camera',
    ],
  ],

metro.config.js

const { getSentryExpoConfig } = require('@sentry/react-native/metro');

const config = getSentryExpoConfig(__dirname);

module.exports = config;

tsconfig.json

{
  "extends": "expo/tsconfig.base",
  "compilerOptions": {
    "strict": true
  },
  "types": ["react", "react-native"],
  "include": [
    "src/**/*.ts",
    "src/**/*.tsx",
    ".eslintrc.js", // Include ESLint configuration file
    "jest.config.js", // Include Jest configuration file
    "metro.config.js", // Include Metro configuration file
    "babel.config.js", // Include Babel configuration file
    "commitlint.config.js", // Include Commitlint configuration file
    "App.tsx" // Include Expo entry point
  ],
  "exclude": ["node_modules"]
}

package.json依赖

"@sentry/react-native": "~6.1.0",

解决办法

这个问题源于旧版本@sentry/react-native(6.1.0)与Expo SDK 52的插件系统不兼容,SDK 52对插件解析逻辑做了调整,而该版本Sentry未适配。以下是验证有效的解决步骤:

  • 升级Sentry依赖到兼容版本
    Expo SDK 52要求@sentry/react-native至少为7.19.0及以上版本,执行升级命令:

    npm install @sentry/react-native@latest
    # 或使用yarn:yarn add @sentry/react-native@latest
    
  • 确认插件配置正确性
    新版本Sentry插件支持可选配置参数,确保app.config.js中的插件配置格式正确(无参数时可保留原结构):

    [
      '@sentry/react-native/expo',
      {
        // 可选配置示例:disableNative: false, enableInExpoDevelopment: true
      }
    ]
    
  • 清除缓存并重建项目
    清理Expo缓存和预构建文件,避免旧缓存干扰:

    npx expo prebuild --clean
    npx expo start --clear
    
  • 验证Metro配置
    新版本getSentryExpoConfig接口未发生破坏性变更,现有metro.config.js无需修改,若仍有报错可检查导入路径是否正确。

已有大量用户遇到相同兼容性问题,升级Sentry依赖到最新兼容版本是最直接有效的解决方式。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.16 06:36:18