ERROR Invariant Violation: Your JavaScript code tried to access a native module that doesn't exist
Asked Answered
I

4

7

I get this error when i run npm run ios :

ERROR Invariant Violation: Your JavaScript code tried to access a native module that doesn't exist.

If you're trying to use a module that is not supported in Expo Go, you need to create a development build of your app. See https://docs.expo.dev/development/introduction/ for more info.

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.

I was programming this code on windows when everything was working but after I migrated to mac everything shut down. Iphone emulator

Imparity answered 21/9, 2022 at 17:13 Comment(0)
C
8

Did you recently attempt to add/use use a new module? I got this exact same error when I attempted to use @react-native-clipboard/clipboard when I should have instead been using expo-clipboard in my Expo app. Toggling to the correct module fixed the problem.

Cinerator answered 23/9, 2022 at 3:5 Comment(0)
E
0

I resolved the issue by removing the react-native-geolocation-service package and ensuring that all instances where it was used were also removed from the project.

Here's what I did:

Unlink and Uninstall the Package: First, I unlinked and uninstalled the react-native-geolocation-service package.

  1. expo unlink react-native-geolocation-service
  2. npm uninstall react-native-geolocation-service

Remove All Usage Instances: I removed all instances where Geolocation from react-native-geolocation-service was used in my project.

Replace with Expo Location API: Instead of using react-native-geolocation-service, I used the expo-location API, which is fully compatible with Expo and works seamlessly across both iOS and Android.

import * as Location from 'expo-location';

Elk answered 12/6 at 12:4 Comment(0)
G
0

Clear Cache: Clearing the cache of your Metro Bundler and your project may help resolve any caching issues that could be causing the error. You can do this by running:

npm start -- --reset-cache

or

yarn start --reset-cache
Guienne answered 12/6 at 12:7 Comment(0)
B
0

For anyone else, getting this error its because I used

import('react-native') inside a function and not at the top level. You may need to use 'require' instead. May have something to do with the webpack bundler. Cost me an hour of time...thanks GPT4

Boswall answered 21/8 at 20:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.