Invariant Violation: OPSQLite could not be found
Closed this issue · 3 comments
Description
When I attempt to use the op-sqlite
to perform any operation, such as opening a connection to a db, it fails with this error:
ERROR Invariant Violation: TurboModuleRegistry.getEnforcing(...): 'OPSQLite' could not be found. Verify that a module by this name is registered in the native binary., js engine: hermes
This problem may be something that I am doing wrong, or a quirk of my dev env. It seems to be saying that something went wrong in the native binary.
Versions:
- MacOS Sonoma
14.3.1
on a MacBook Pro M1 Max (ARM) - Simulator iOS version:
17.0
- op-sqlite version:
2.0.18
- RN version:
0.72.7
Reproducible example
When I import this code sample into my app.tsx
file it causes the error.
import { open } from "@op-engineering/op-sqlite"
const db = open({ name: 'myDb.sqlite' })
![Screenshot of the error in Terminal and iOS Simulator](https://private-user-images.githubusercontent.com/15811/304564766-7223bbd4-74ee-4fd0-9449-44d1828eeff5.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjA0NTUyNTEsIm5iZiI6MTcyMDQ1NDk1MSwicGF0aCI6Ii8xNTgxMS8zMDQ1NjQ3NjYtNzIyM2JiZDQtNzRlZS00ZmQwLTk0NDktNDRkMTgyOGVlZmY1LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA3MDglMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNzA4VDE2MDkxMVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWJmNDc0OWExNzkyNGI2NGUzMjdkNTEwMmI4NmRkZjQ4N2U0MTBiNzU5NGMzY2U5YTI2YzBhNTJiNzdkZDYzYTEmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.I2YwCTonkyZKqcpxdnE9eXNjZpBvEHYBQgZoWac30T8)
I'm still missing some data. It looks you might be using the new arch, which might be causing some issues. You need to create a minimal reproducible example for me to take a look at.
Edit: tried a brand new project with the new arch enabled. Everything is working. There is something wrong with your project. Try clearing the caches, re-installing pods, etc.
![](https://private-user-images.githubusercontent.com/1634213/304652682-a52d4ec7-7e4f-4a27-bec2-a588ffc9e3b1.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjA0NTUyNTIsIm5iZiI6MTcyMDQ1NDk1MiwicGF0aCI6Ii8xNjM0MjEzLzMwNDY1MjY4Mi1hNTJkNGVjNy03ZTRmLTRhMjctYmVjMi1hNTg4ZmZjOWUzYjEucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI0MDcwOCUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNDA3MDhUMTYwOTEyWiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9NGVlMmQwMjE3ZGM0YzExMDEyYTIyNTBlNjA5M2I0ZjllODY0ZGY2NWZlMmVlNDgxM2NhYzhmZDY3ZGJmZmYwNyZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QmYWN0b3JfaWQ9MCZrZXlfaWQ9MCZyZXBvX2lkPTAifQ.5ugLeLCinAvL_cIzl3kdHuBHzf6tMHoTgvT7NhthUL8)
I got this working in my environment, and this may help others in my situation.
The version of React Native I am using, 0.72.7
is a "new arch" version but support in the native build processes is not enabled by default, there are additional steps.
As described on a separate page in the the React Native docs, to enable the the New Architecture on iOS:
RCT_NEW_ARCH_ENABLED=1 npx pod-install
npm run ios
(If first time running pod install then you will want to do this first:)
RCT_NEW_ARCH_ENABLED=1 npx expo prebuild
And for Android as described in the React Native docs, edit android/gradle.properties
:
newArchEnabled=true
And then run the app to build:
npm run android
And then I am able to use op-sqlite
without errors.
Perhaps this should be added to the documentation so that other people dont have the same problem.
Enabling the new arch is a general procedure for RN and does not affect op-sqlite. The module correctly links if you have enabled it and ran pod install correctly, so nothing to do here.