使用新架构构建Android应用时出现Turbo Module缺失错误
解决React Native + Expo环境下PlatformConstants Turbo Module缺失错误
问题详情
构建成功后抛出以下错误:
早期Js错误:Turbo Module Registry.getEnforcing(...):未找到'PlatformConstants'。请确认该模块已在原生二进制文件中注册。无桥接模式:已启用。Turbo Module互操作:已启用。已加载模块:("NativeModules":[],"TurboModules": {"未找到": ["NativePerformanceObserverCxx","NativePerformanceCxx","PlatformConstants"]})
已尝试过同类缺失模块的解决方案,但均无效。
当前package.json配置
{ "devDependencies": { "@babel/core": "^7.25.2", "@babel/plugin-proposal-nullish-coalescing-operator": "^7.18.6", "@babel/plugin-proposal-optional-chaining": "^7.21.0", "@babel/preset-env": "^7.25.4", "@babel/runtime": "^7.25.6", "@react-native/eslint-config": "0.75.2", "@react-native/metro-config": "0.75.2", "@react-native/typescript-config": "0.75.2", "@types/react": "^18.3.5", "@types/react-native-background-timer": "^2.0.2", "@types/react-native-dotenv": "^0.2.2", "@types/react-test-renderer": "^18.3.0", "babel-jest": "^29.7.0", "babel-plugin-module-resolver": "^5.0.2", "babel-plugin-transform-remove-console": "^6.9.4", "eslint": "^9.9.1", "jest": "^29.7.0", "prettier": "^3.3.3", "react-native-dotenv": "^3.4.11", "react-native-flipper-performance-plugin": "^0.4.0", "react-test-renderer": "18.3.1", "typescript": "5.5.4" }, "dependencies": { "@expo/config": "^9.0.3", "@expo/env": "^0.3.0", "@hookform/resolvers": "^3.9.0", "@react-native-async-storage/async-storage": "^2.0.0", "@react-native-community/checkbox": "^0.5.17", "@react-native-community/hooks": "^3.0.0", "@react-native/codegen": "0.75.2", "@react-native/metro-config": "^0.75.2", "@react-navigation/native": "^6.1.18", "@react-navigation/native-stack": "^6.11.0", "@react-three/fiber": "^8.17.6", "@reduxjs/toolkit": "^2.2.7", "@sentry/react-native": "^5.31.1", "@shopify/react-native-skia": "^1.3.11", "@types/lodash": "^4.17.7", "@types/three": "^0.168.0", "axios": "^1.7.7", "base64-arraybuffer": "^1.0.2", "dayjs": "^1.11.13", "expo": "51.0.32", "expo-asset": "^10.0.10", "expo-av": "~14.0.7", "expo-constants": "~16.0.2", "expo-file-system": "~17.0.1", "expo-font": "~12.0.10", "expo-gl": "~14.0.2", "expo-modules-core": "^1.12.24", "expo-screen-orientation": "~7.0.5", "expo-sqlite": "~14.0.6", "immer": "^10.1.1", "lodash": "^4.17.21", "react": "18.3.1", "react-hook-form": "^7.53.0", "react-icomoon": "^2.5.7", "react-native": "0.75.2", "react-native-background-timer": "^2.4.1", "react-native-ble-manager": "^11.5.5", "react-native-confirmation-code-field": "^7.4.0", "react-native-fs": "^2.20.0", "react-native-geolocation-service": "^5.3.1", "react-native-gesture-handler": "~2.19.0", "react-native-just-checkbox": "^2.0.15", "react-native-logs": "^5.1.0", "react-native-material-menu": "^2.0.0", "react-native-radio-buttons-group": "^3.1.0", "react-native-reanimated": "3.15.1", "react-native-redash": "^18.1.3", "react-native-safe-area-context": "^4.10.9", "react-native-screens": "~3.34.0", "react-native-svg": "^15.6.0", "react-native-svg-transformer": "^1.5.0", "react-native-system-setting": "^1.7.6", "react-native-toast-notifications": "^3.4.0", "react-native-ui-datepicker": "^2.0.3", "react-native-walkthrough-tooltip": "^1.6.0", "react-native-wifi-reborn": "^4.12.1", "react-redux": "^9.1.2", "rn-animated-ellipsis": "^2.1.3", "three": "0.168.0", "three-stdlib": "^2.32.2", "victory-native": "^41.1.1", "yup": "^1.4.0", "zustand": "^4.5.5" } }
解决方案步骤
1. 彻底清除缓存
缓存不一致是这类问题的常见诱因,执行以下操作:
- 重置Metro缓存:
npx react-native start --reset-cache - 删除依赖文件后重装:
rm -rf node_modules package-lock.json && npm install - iOS端清理Pods:
cd ios && rm -rf Pods Podfile.lock && pod install && cd .. - Android端清理Gradle:
cd android && ./gradlew clean && cd ..
2. 验证Expo Constants配置
PlatformConstants由expo-constants提供,确保配置正确:
- 在
app.json或app.config.js中确认插件已添加:{ "expo": { "plugins": ["expo-constants"] } } - 若使用裸工作流,重新生成原生文件:
npx expo prebuild --clean
3. 临时禁用Bridgeless模式
错误显示当前启用了无桥接模式,部分第三方库可能未适配该模式,可临时禁用验证:
在metro.config.js中添加以下配置:
const { getDefaultConfig } = require('@react-native/metro-config'); const config = getDefaultConfig(__dirname); // 禁用Bridgeless模式 config.server.environment = { ...config.server.environment, REACT_NATIVE_BRIDGELESS: '0', }; module.exports = config;
4. 排查第三方依赖兼容性
错误中同时缺失性能相关模块,重点排查以下依赖:
- 暂时移除
react-native-flipper-performance-plugin,重新构建测试 - 检查
@sentry/react-native版本是否适配RN 0.75.2,尝试升级至最新兼容版本(如^5.34.0)
内容的提问来源于stack exchange,提问作者SET_RED_EYES
相关产品推荐
相关产品推荐

