React Native + Expo项目构建时无法解析@sentry-internal/replay依赖的问题求助
React Native + Expo项目构建时无法解析@sentry-internal/replay依赖的问题求助
大家好,我最近在维护一个React Native + Expo项目,构建过程中遇到了一个依赖解析的报错,卡了好长时间都没搞定,想请教下各位有没有遇到过类似的问题,或者有什么解决思路?
项目环境信息
- Node版本:
v18.18.2 - Expo SDK版本:
52 - package.json中engines配置:
"engines": { "node": ">=18" }
项目的dependencies配置如下:
"dependencies": { "@expo-google-fonts/roboto": "^0.2.3", "@expo/config-plugins": "~9.0.0", "@expo/vector-icons": "^14.0.0", "@gorhom/bottom-sheet": "^4.4.5", "@react-native-async-storage/async-storage": "1.23.1", "@react-native-community/datetimepicker": "8.2.0", "@react-native-community/netinfo": "11.4.1", "@react-navigation/bottom-tabs": "^6.5.7", "@react-navigation/native": "^6.1.6", "@react-navigation/native-stack": "^6.9.12", "@react-navigation/stack": "^6.3.16", "@sentry/react-native": "~6.3.0", "@xstate/react": "^3.2.1", "base32.js": "^0.1.0", "big.js": "^5.0.3", "bitcoin-address-validation": "^2.1.0", "buffer": "^5.2.1", "color-alpha": "^1.1.3", "country-list": "^2.1.0", "crc": "^3.8.0", "deprecated-react-native-prop-types": "^4.0.0", "dotenv": "^16.0.3", "expo": "^52.0.0", "expo-application": "~6.0.1", "expo-asset": "~11.0.1", "expo-camera": "~16.0.10", "expo-clipboard": "~7.0.0", "expo-constants": "~17.0.3", "expo-contacts": "~14.0.2", "expo-device": "~7.0.1", "expo-document-picker": "~13.0.1", "expo-image-manipulator": "~13.0.5", "expo-image-picker": "~16.0.3", "expo-linear-gradient": "~14.0.1", "expo-linking": "~7.0.3", "expo-local-authentication": "~15.0.1", "expo-localization": "~16.0.0", "expo-location": "~18.0.4", "expo-notifications": "~0.29.11", "expo-secure-store": "~14.0.0", "expo-splash-screen": "~0.29.18", "expo-status-bar": "~2.0.0", "expo-system-ui": "~4.0.6", "expo-updates": "~0.26.10", "expo-web-browser": "~14.0.1", "formik": "^2.2.9", "google-libphonenumber": "^3.2.27", "hoist-non-react-statics": "^3.3.2", "i18n-js": "^3.8.0", "i18next": "^21.4.2", "is-valid-domain": "^0.1.6", "jssha": "^2.3.1", "lodash": "^4.17.21", "lottie-react-native": "7.1.0", "metro-react-native-babel-transformer": "^0.77.0", "moment": "^2.29.1", "moment-timezone": "^0.5.32", "node-libs-react-native": "^1.2.1", "patch-package": "^6.5.1", "postinstall-postinstall": "^2.1.0", "prop-types": "^15.8.1", "query-string": "^7.1.1", "react": "18.3.1", "react-dom": "18.3.1", "react-hook-form": "^7.43.9", "react-i18next": "^11.14.2", "react-native": "0.76.5", "react-native-animatable": "^1.3.3", "react-native-app-link": "^1.0.1", "react-native-circular-progress": "^1.3.8", "react-native-collapsible": "^1.6.1", "react-native-country-picker-modal": "^2.0.0", "react-native-gesture-handler": "~2.20.2", "react-native-markdown-display": "^7.0.0-alpha.2", "react-native-masked-text": "^1.13.0", "react-native-modal": "^13.0.1", "react-native-modal-datetime-picker": "^14.0.1", "react-native-pager-view": "6.5.1", "react-native-phone-number-input": "^2.1.0", "react-native-picker-select": "^8.0.4", "react-native-popover-view": "^5.1.7", "react-native-qrcode-svg": "^6.2.0", "react-native-reanimated": "~3.16.1", "react-native-round-flags": "^1.0.4", "react-native-safe-area-context": "4.12.0", "react-native-screens": "~4.4.0", "react-native-skeleton-placeholder": "^5.2.4", "react-native-snap-carousel": "4.0.0-beta.6", "react-native-super-grid": "^5.0.0", "react-native-svg": "15.8.0", "react-native-svg-transformer": "^1.0.0", "react-native-tab-view": "^3.5.1", "react-native-web": "~0.19.10", "react-native-webview": "13.12.5", "react-query": "^3.39.3", "react-redux": "^8.0.5", "redux": "^4.2.1", "redux-persist": "^6.0.0", "redux-saga": "^1.2.3", "redux-thunk": "^2.4.2", "reselect": "^4.1.7", "rn-material-ui-textfield": "^1.0.9", "stellar-sdk": "^8.2.3", "xstate": "^4.37.1", "yup": "^0.26.6" },
Metro配置
const { getSentryExpoConfig } = require("@sentry/react-native/metro"); const config = getSentryExpoConfig(__dirname); const { transformer, resolver } = config; config.transformer = { ...transformer, babelTransformerPath: require.resolve('react-native-svg-transformer'), }; config.resolver = { ...resolver, assetExts: resolver.assetExts.filter(ext => ext !== 'svg'), sourceExts: [...resolver.sourceExts, 'svg'], extraNodeModules: require('node-libs-react-native'), }; module.exports = config;
App.js入口配置
import App from './src'; require('node-libs-react-native/globals'); import Constants from 'expo-constants'; import * as Sentry from '@sentry/react-native'; // TODO: This constants format will change when we upgrade to the new Expo SDK. Sentry.init({ dsn: Constants.expoConfig?.extra?.eas?.sentryDSN ?? Constants.manifest2?.extra?.expoClient?.extra?.eas?.sentryDSN, debug: true, }); export default Sentry.wrap(App);
遇到的错误
构建项目时出现以下报错:
iOS Bundling failed 2276ms index.js (4106 modules)
Unable to resolve "@sentry-internal/replay" from "node_modules/@sentry/browser/build/npm/cjs/index.js"
我查看了依赖包内部的代码,发现@sentry/react-native里有一行代码是这样引入的:
const replay = require('@sentry-internal/replay');
已尝试的解决方法
我已经试过谷歌搜索相关问题、用AI工具排查、逛Stack Overflow找类似案例,但都没找到能解决这个问题的方案。
有没有朋友遇到过类似的情况?或者能给我一些排查的方向?非常感谢!
备注:内容来源于stack exchange,提问作者Ajoy_Sarker
相关产品推荐
相关产品推荐

