OP-Engineering / op-sqlite

Fastest SQLite library for react-native by @ospfranco
MIT License
402 stars 23 forks source link

Invariant Violation: OPSQLite could not be found #52

Closed gvt closed 3 months ago

gvt commented 3 months ago

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:

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
ospfranco commented 3 months ago

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.

gvt commented 3 months ago

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.

ospfranco commented 3 months ago

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.