Invariant Violation: Metro is run from the wrong folder issue

The error message “Invariant Violation: Metro is run from wrong folder issue” typically occurs when there is a mismatch between the expected project folder and the actual folder where the Metro bundler is running. This often happens in React Native projects.

Figure: Invariant Violation Error

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

Check Current Directory:
Ensure that you are in the correct directory of your React Native project. Navigate to the root folder of your project using the cd command:

Delete Node Modules and Reinstall:
Remove the node_modules folder and the package-lock.json or yarn.lock file, then reinstall dependencies:

Restart Metro Bundler:
Stop the Metro bundler and restart it:

If you are still getting the issue, then open the app.json file of the project and check the “name” and “displayName“. The name should be the same as that you are getting in the error message as shown in the figures below.

Figure: Error Message
Figure: app.json file
Ads:

That’s it for this blog. I hope, this blog really helped you to fix the issue. if you have any queries or suggestions. You can connect with us through the contact section. We are also available on YouTube. You can also follow the video given below.

Subscribe!

Leave a Reply

Your email address will not be published. Required fields are marked *