Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prisma Integration Errors in React Native with Expo: Warnings and Import Failures #16

Open
nabilhayek opened this issue Jun 1, 2024 · 10 comments · May be fixed by #20
Open

Prisma Integration Errors in React Native with Expo: Warnings and Import Failures #16

nabilhayek opened this issue Jun 1, 2024 · 10 comments · May be fixed by #20

Comments

@nabilhayek
Copy link
Contributor

Description

When following documentation for in README.md according to the Expo Section I get various warinings/errors in different scenarios.

  1. Creating a PrismaClient instance anywhere in the application gives this warning
    image
  2. Importing import '@prisma/react-native'; anywhere in the application throws this error
    image

Expected Behavior

When following the guidelines outlined in the README.md under the Expo Section, users should be able to integrate Prisma seamlessly into their React Native projects using Expo without encountering warnings or errors mentioned.

Additional Information

The issues described above were observed not only when using the Expo Go app for live testing and development but also during local builds of the application. This was done to ensure that the problems were consistent across different testing environments provided by Expo. Despite trying various configurations and setups in both Expo Go and local builds, the same warnings and errors persisted.

@nabilhayek
Copy link
Contributor Author

Issue seems to be related to NativeModules returning an empty object. Trying to reference to NativeModules.Prisma which will give null.
Output: NativeModules {}

const PrismaModule = isTurboModuleEnabled
? require('./NativePrisma').default
: NativeModules.Prisma;
if (!PrismaModule) {
throw new Error('🟥 @prisma/react-native failed to initialize');
}

@sorenbs
Copy link
Member

sorenbs commented Jun 4, 2024

Thank you for reporting this Nabil.

To help me narrow this down, can you confirm that you are doing the following:

  1. Adding the Expo plugin "plugins": ["@prisma/react-native"] and running prebuild npx expo prebuild --clean
  2. setting previewFeatures = ["reactNative"] in the schema as per the readme
  3. generate initial migrations and a database if it doesn't exist: npx prisma@latest migrate dev
  4. generating the client: npx prisma@latest generate
  5. running prebuild to activate the Expo plugin

Prisma relies on a native module, so Expo Go isn't supported at the moment.

@Skr1pt1k
Copy link

Skr1pt1k commented Jun 7, 2024

Thank you for reporting this Nabil.

To help me narrow this down, can you confirm that you are doing the following:

  1. Adding the Expo plugin "plugins": ["@prisma/react-native"] and running prebuild npx expo prebuild --clean
  2. setting previewFeatures = ["reactNative"] in the schema as per the readme
  3. generate initial migrations and a database if it doesn't exist: npx prisma@latest migrate dev
  4. generating the client: npx prisma@latest generate
  5. running prebuild to activate the Expo plugin

Prisma relies on a native module, so Expo Go isn't supported at the moment.

I'm facing same issue. I've tried all steps above, but prisma failed to initialize

hassankhan added a commit to twodoorsdev/react-native-prisma that referenced this issue Jun 8, 2024
…rrors

Show a few common error resolutions when the native module fails to initialize for any reason.

Partially resolves prisma#16.
hassankhan added a commit to twodoorsdev/react-native-prisma that referenced this issue Jun 8, 2024
…rors

Show a few common resolutions when the native module fails to initialize for any reason.

Partially resolves prisma#16.
hassankhan added a commit to twodoorsdev/react-native-prisma that referenced this issue Jun 8, 2024
…rors

Show a few common resolutions when the native module fails to initialize for any reason.

Partially resolves prisma#16.
hassankhan added a commit to twodoorsdev/react-native-prisma that referenced this issue Jun 8, 2024
…rors

Show a few common resolutions when the native module fails to initialize for any reason.

Partially resolves prisma#16.
@sorenbs
Copy link
Member

sorenbs commented Jun 9, 2024

Thanks @Skr1pt1k. Now, I'm wondering what's special about your setup. Would you be able to invite me to a repo or create a minimal reproduction I can debug?

@Daemon-25
Copy link

Daemon-25 commented Jul 7, 2024

I was able to recreate this issue and even solve it I don't know why but when you define the sceham.prisma in some ./**/ directory the prisma is not able to initialize or sometimes access the database same goes for many other issues created on this repo. I was even able to solve it by creating the schema.prisma in the ROOT_DIR of the project which then allows PrismaClient to work perfectly as expected. Other issues which I faced was

  1. main.Table not found due to the reason PrismaClient cannot access the DB
  2. property __PrismaProxy doesnot exist
  3. @prisma/react-native failed to initialize, js-engine hermes

@mathieupost
Copy link

mathieupost commented Aug 26, 2024

Also having this issue. Interesting is that I don't have the issue with the example project https://github.com/sorenbs/budget-buddy-expo. I tried installing the same version of all prisma dependencies in the package.json from that project and mirroring configuration as closely as possible, but I still can't get rid of the error in my own project...

Edit: also working in a new project created with create-expo-app

@schaier-io
Copy link

schaier-io commented Aug 26, 2024

I figuerd out for me the problem was

  1. Do not run it under expo go but on device via npx expo run:android --device (substitute android for ios if needed) and do not connect via the QR code or the app
  2. Make sure to have the prisma file in the root directory
  3. ONLY use it with the extended client, never use the normal client without extension. Working for me was the following code I borrowed from https://github.com/sorenbs/budget-buddy-expo
    Just use the exported prisma client and it worked
import '@prisma/client/react-native';
import { PrismaClient } from '@prisma/client/react-native';
import { reactiveHooksExtension } from "@prisma/react-native";

const basePrisma = new PrismaClient()
basePrisma.$applyPendingMigrations();
export const prisma = basePrisma.$extends(reactiveHooksExtension());

PS: Make sure to run npx prisma generate
npx expo prebuild --clean before all

EDIT: I still receive the error in the console sometimes when reloading, however afterward it initializes fine, applies the migrations without problems and runs all queries. Maybe try if it works for you too

@godwinmat
Copy link

What version of prisma, @prisma/client and @prisma/react-native are you using

@bogdan-arsene
Copy link

The issue also persists for me, even when I run the base project from @sorenbs : https://github.com/sorenbs/budget-buddy-expo with all the prerequisites steps mentioned above. Any potential fixes?

@abc-tiago
Copy link

Estou com mesmo problema....

"@prisma/client": "^5.22.0",
"@prisma/react-native": "^5.22.0",
react-native-quick-base64

Task :prisma_react-native:configureCMakeDebug[arm64-v8a] FAILED
C/C++: CMake Error at CMakeLists.txt:10 (add_library):
C/C++: Target "react-native-prisma" links to target
C/C++: "ReactAndroid::turbomodulejsijni" but the target was not found. Perhaps a
C/C++: find_package() call is missing for an IMPORTED target, or an ALIAS target
C/C++: is missing?
C/C++: CMake Error at CMakeLists.txt:10 (add_library):
C/C++: Target "react-native-prisma" links to target
C/C++: "ReactAndroid::react_nativemodule_core" but the target was not found.
C/C++: Perhaps a find_package() call is missing for an IMPORTED target, or an
C/C++: ALIAS target is missing?
C/C++: CMake Generate step failed. Build files cannot be regenerated correctly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
9 participants