skip to Main Content

I am trying to run my React Native Expo app, but I am facing this error:

 ERROR  TypeError: Cannot read property 'getConstants' of null, js engine: hermes
 ERROR  Invariant Violation: "main" has not been registered. This can happen if:
* Metro (the local dev server) is run from the wrong folder. Check if Metro is running, stop it and restart it in the current project.
* A module failed to load due to an error and `AppRegistry.registerComponent` wasn't called., js engine: hermes

I tried to add "jsEngine": "hermes" to my app.json file, but I am still getting that error.

2

Answers


  1. The error you’re encountering seems to be related to the JavaScript engine being used by your React Native Expo app. Hermes is a JavaScript engine optimized for running React Native apps, and it’s the default engine in Expo.

    Here are some steps you can take to troubleshoot and resolve this issue:

    1. Clear Cache:
      Try clearing the Metro bundler cache and the watchman watch-list. You can do this by running the following commands in your project directory:

      watchman watch-del-all
      rm -rf node_modules
      rm -rf /tmp/metro-*
      npm cache clean --force
      npm install
      

      Then, try running your app again.

    2. Check Dependencies:
      Make sure your app’s dependencies are up to date. Run the following command to update all dependencies in your project:

      npm update
      

      Additionally, check for any deprecated or incompatible dependencies in your package.json and update them as needed.

    3. Verify Project Structure:
      Ensure that you are running Metro from the correct project directory. You should be in the root directory of your React Native Expo project when you run the npm start or expo start command.

    4. Check for Module Errors:
      The "Invariant Violation" error often indicates a problem with one of your JavaScript modules. Review your code for any issues or missing imports. Also, check if you have correctly called AppRegistry.registerComponent in your entry file (usually index.js).

    5. Downgrade Hermes:
      If you still encounter issues with Hermes, you can try downgrading to the older version by adding the following to your app.json:

      "hermes": {
        "enabled": true,
        "commandUnlink": "node node_modules/hermes-engine/unlink"
      }
      

      This might help if there is an issue with the version of Hermes being used.

    6. Verify Node and npm:
      Make sure you are using compatible versions of Node.js and npm. Check the required versions for your Expo and React Native versions in your project’s documentation and ensure you have them installed.

    7. Check Environment Variables:
      Ensure that you don’t have any conflicting environment variables that could affect your app’s behavior. Check for any environment variables related to your JavaScript engine settings.

    8. Check for Other Errors:
      Review your project for any other errors in the code, and inspect the console output for more specific error messages that might give you additional clues about what’s causing the problem.

    If you’ve tried all of these steps and are still experiencing the issue, please provide more information about your project, such as your package.json file, any additional error messages, and the structure of your project, so I can offer more specific assistance.

    Login or Signup to reply.
  2. I see the same problem, on Android only, when importing the package ‘react-native-blob-util’.

    Steps to reproduce:

    1. Create a brand new project with npx create-expo-app reproApp
    2. npm install --save react-native-blob-util
    3. Add this line to App.js: import ReactNativeBlobUtil from 'react-native-blob-util';
    4. npx expo start and a for Android

    It fails immediately with this error:

    ERROR  TypeError: Cannot read property 'getConstants' of null, js engine: hermes
     ERROR  Invariant Violation: "main" has not been registered. This can happen if:
    * Metro (the local dev server) is run from the wrong folder. Check if Metro is running, stop it and restart it in the current project.
    * A module failed to load due to an error and `AppRegistry.registerComponent` wasn't called., js engine: hermes
    

    This is on Node 18.18.2.
    Here is package.json:

    {
      "name": "androidtest",
      "version": "1.0.0",
      "main": "node_modules/expo/AppEntry.js",
      "scripts": {
        "start": "expo start",
        "android": "expo start --android",
        "ios": "expo start --ios",
        "web": "expo start --web"
      },
      "dependencies": {
        "expo": "~49.0.15",
        "expo-status-bar": "~1.6.0",
        "react": "18.2.0",
        "react-native": "0.72.6",
        "react-native-blob-util": "^0.19.6"
      },
      "devDependencies": {
        "@babel/core": "^7.20.0"
      },
      "private": true
    }
    
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search