Expo React Native iOS端调试异常求助(Hermes/JSC均失效)
iOS Expo React Native 调试故障排查(Hermes/JSC 均无法调试)
我用Expo开发React Native项目,iOS端不管在app.json里把jsEngine设为Hermes还是JSC,都没法用Chrome DevTools(Metro运行时按"j")或其他调试环境,具体问题:
- Hermes模式下按"j",提示:
Debug: No compatible apps connected. JavaScript Debugging can only be used with the Hermes engine. - JSC模式下打包加载到98%超时,提示无法连接开发服务器
- Hermes模式下Mac按
command+D唤出菜单,没有调试选项
项目入口是package.json指定的expo/AppEntry.js,Android端用Hermes能正常运行调试,因为react-native-firebase兼容性问题没法用Expo Go。
项目配置文件
app.json
{ "expo": { "name": "NatureCounter", "slug": "NatureCounter", "version": "1.0.0", "orientation": "portrait", "icon": "./assets/icon.png", "jsEngine": "hermes", "userInterfaceStyle": "light", "splash": { "image": "./assets/splash.png", "resizeMode": "contain", "backgroundColor": "#ffffff" }, "ios": { "supportsTablet": true, "bundleIdentifier": "crowddoing.world.naturecounter" }, "android": { "adaptiveIcon": { "foregroundImage": "./assets/adaptive-icon.png", "backgroundColor": "#ffffff" }, "package": "com.naturecounter" }, "web": { "favicon": "./assets/favicon.png" }, "extra": { "eas": { "projectId": "bed483af-b658-4941-8cc1-a909337111a1" } } } }
package.json
{ "name": "NatureCounter", "version": "1.0.0", "main": "expo/AppEntry.js", "scripts": { "start": "expo start", "android": "expo run:android", "ios": "expo run:ios", "web": "expo start --web" }, "dependencies": { "@react-native-async-storage/async-storage": "^2.0.0", "@react-native-community/checkbox": "^0.5.17", "@react-native-community/datetimepicker": "^8.2.0", "@react-native-community/netinfo": "11.3.1", "@react-native-firebase/app": "^21.0.0", "@react-native-firebase/auth": "^21.0.0", "@react-native-firebase/dynamic-links": "^21.0.0", "@react-native-firebase/firestore": "^21.0.0", "@react-native-firebase/installations": "^21.0.0", "@react-native-picker/picker": "^2.8.1", "@react-navigation/bottom-tabs": "^6.6.1", "@react-navigation/drawer": "^6.7.2", "@react-navigation/native": "^6.1.18", "@react-navigation/stack": "^6.4.1", "@reduxjs/toolkit": "^2.2.7", "@shopify/react-native-skia": "^1.4.1", "@types/react": "~18.2.79", "axios": "^1.7.7", "axios-rate-limit": "^1.4.0", "expo": "~51.0.28", "expo-status-bar": "~1.12.1", "immutable": "^4.3.7", "lodash": "^4.17.21", "lottie-react-native": "^7.0.0", "moment": "^2.30.1", "native-base": "^3.4.28", "rand-seed": "^2.1.7", "react": "18.2.0", "react-native": "0.74.5", "react-native-background-fetch": "^4.2.7", "react-native-bluetooth-status": "^1.5.1", "react-native-bouncy-checkbox": "^4.1.2", "react-native-calendars": "^1.1307.0", "react-native-chart-kit": "^6.12.0", "react-native-devsettings": "^1.0.5", "react-native-easy-grid": "^0.2.2", "react-native-elements": "^3.4.3", "react-native-extra-dimensions-android": "^1.2.5", "react-native-fbsdk-next": "^13.1.1", "react-native-fs": "^2.20.0", "react-native-geolocation-service": "^5.3.1", "react-native-gesture-handler": "~2.16.1", "react-native-get-random-values": "^1.11.0", "react-native-image-picker": "^7.1.2", "react-native-linear-gradient": "^2.8.3", "react-native-maps": "^1.18.0", "react-native-modal": "^13.0.1", "react-native-outside-press": "^1.2.2", "react-native-paper": "^5.12.5", "react-native-paper-dates": "^0.22.26", "react-native-permissions": "^5.0.2", "react-native-raw-bottom-sheet": "^3.0.0", "react-native-reanimated": "3.16.1", "react-native-reanimated-carousel": "4.0.0-alpha.12", "react-native-redash": "16.2.2", "react-native-render-html": "^6.3.4", "react-native-safe-area-context": "^4.11.0", "react-native-scroll-bottom-sheet": "^0.7.0", "react-native-simple-time-picker": "^1.3.11", "react-native-simple-toast": "^3.3.1", "react-native-svg": "^15.7.1", "react-native-svg-uri": "^1.2.3", "react-native-vector-icons": "^10.2.0", "react-native-video": "^6.6.3", "react-native-wheel-pick": "^1.2.2", "react-redux": "^9.1.2", "realm": "^12.13.1", "redux-actions": "2.6.5", "redux-devtools-extension": "^2.13.9", "redux-immutable": "^4.0.0", "redux-logger": "^3.0.6", "redux-persist": "^6.0.0", "redux-thunk": "^3.1.0", "rn-fetch-blob": "^0.12.0", "styled-components": "^6.1.14", "typescript": "~5.3.3", "victory-native": "^41.4.0" }, "devDependencies": { "@babel/core": "^7.20.0", "react-native-svg-transformer": "^1.5.0" }, "private": true }
调试配置修复方案
针对Hermes模式调试问题
- 开启iOS原生调试信息
打开Xcode中的iOS项目(路径:ios/NatureCounter.xcworkspace),进入项目target的Build Settings,搜索DEBUG_INFORMATION_FORMAT,确保Debug模式下设置为DWARF with dSYM File。 - 添加Hermes调试配置
在app.json的ios节点中补充配置:"ios": { "supportsTablet": true, "bundleIdentifier": "crowddoing.world.naturecounter", "jsEngine": "hermes", "debuggerHost": "localhost:8081" } - 重置Metro缓存
执行命令:
之后重新运行expo start --clearexpo run:ios。 - 检查网络连接
确保iOS设备/模拟器和Mac在同一局域网,或通过USB连接设备并开启网络共享。
针对JSC模式连接超时问题
- 添加JSC调试端口配置
在app.json的ios节点中设置:"ios": { "supportsTablet": true, "bundleIdentifier": "crowddoing.world.naturecounter", "jsEngine": "jsc", "debuggerHost": "localhost:8081" } - 检查防火墙设置
确认Mac防火墙允许Metro服务器(端口8081)的网络连接。 - 指定本地IP启动Metro
执行:
再重新运行iOS项目。expo start --localhost --clear
通用调试菜单修复
- 强制Debug模式构建
运行iOS项目时明确指定Debug配置:expo run:ios --configuration Debug - 重置设备缓存
- 模拟器:执行
Device -> Erase All Content and Settings - 真机:卸载App后重新安装
- 模拟器:执行
内容的提问来源于stack exchange,提问作者Mike Putnam
相关产品推荐
相关产品推荐

