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
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:
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:
Then, try running your app again.
Check Dependencies:
Make sure your app’s dependencies are up to date. Run the following command to update all dependencies in your project:
Additionally, check for any deprecated or incompatible dependencies in your
package.json
and update them as needed.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
orexpo start
command.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 (usuallyindex.js
).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
:This might help if there is an issue with the version of Hermes being used.
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.
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.
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.I see the same problem, on Android only, when importing the package ‘react-native-blob-util’.
Steps to reproduce:
npx create-expo-app reproApp
npm install --save react-native-blob-util
import ReactNativeBlobUtil from 'react-native-blob-util';
npx expo start
anda
for AndroidIt fails immediately with this error:
This is on Node 18.18.2.
Here is package.json: