androidreact-nativeexpo

expo react native error: TurboModuleRegistry.getEnforcing(...): 'PlatformConstants'


When I start my npx expo run:android project like this, I get the error:

ERROR Invariant Violation: TurboModuleRegistry.getEnforcing(...): 'PlatformConstants' could not be found. Verify that a module by this name is registered in the native binary., js engine: hermes

  "dependencies": {
"@expo/vector-icons": "^14.1.0",
"@react-native-picker/picker": "2.11.0",
"@react-navigation/bottom-tabs": "^7.3.10",
"@react-navigation/elements": "^2.3.8",
"@react-navigation/native": "^7.1.6",
"appwrite": "^17.0.2",
"axios": "^1.9.0",
"expo": "~53.0.7",
"expo-blur": "~14.1.4",
"expo-constants": "~17.1.5",
"expo-dev-client": "^5.1.8",
"expo-font": "~13.3.1",
"expo-haptics": "~14.1.4",
"expo-image": "~2.1.6",
"expo-image-picker": "~16.1.4",
"expo-linear-gradient": "~14.1.4",
"expo-linking": "~7.1.4",
"expo-router": "~5.0.5",
"expo-splash-screen": "~0.30.8",
"expo-status-bar": "~2.2.3",
"expo-symbols": "~0.4.4",
"expo-system-ui": "~5.0.7",
"expo-web-browser": "~14.1.6",
"nativewind": "^4.1.23",
"react": "19.0.0",
"react-dom": "19.0.0",
"react-native": "0.79.2",
"react-native-appwrite": "^0.7.3",
"react-native-gesture-handler": "~2.24.0",
"react-native-reanimated": "^3.17.5",
"react-native-safe-area-context": "^5.4.0",
"react-native-screens": "~4.10.0",
"react-native-web": "~0.20.0",
"react-native-webview": "13.13.5",
"expo-location": "~18.1.4"

},

 "devDependencies": {
"@babel/core": "^7.25.2",
"@types/react": "~19.0.10",
"autoprefixer": "^10.4.21",
"eslint": "^9.25.0",
"eslint-config-expo": "~9.2.0",
"postcss": "^8.5.3",
"tailwindcss": "^3.4.17",
"typescript": "~5.8.3"

},

I tried many ways but it is not solved and I could not find it in any source.


Solution

  • If you edit the files as I gave you, it will be solved. (if these files do not exist, you create them.)

    metro.config.json:

    const { getDefaultConfig } = require("expo/metro-config");
    const { withNativeWind } = require('nativewind/metro');
    
    const config = getDefaultConfig(__dirname);
    
    // Add additional resolver for React Native
    config.resolver.sourceExts = [...config.resolver.sourceExts, 'mjs'];
    config.resolver.extraNodeModules = {
      ...config.resolver.extraNodeModules,
      'react-native': require.resolve('react-native'),
    };
    
    // Add support for Hermes
    config.transformer.unstable_allowRequireContext = true;
    
    module.exports = withNativeWind(config, { input: './global.css' });
    

    app.json:

    "newArchEnabled": false,
    

    babel.config.js

    plugins: [
            "react-native-reanimated/plugin",
            ["module-resolver", {
              alias: {
                "^react-native$": "react-native"
              }
            }]
          ]
    

    then run on the terminal:

    npx expo prebuild --clean && npx expo run:android