prisma / react-native-prisma

Apache License 2.0
200 stars 9 forks source link

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

Open nabilhayek opened 5 months ago

nabilhayek commented 5 months ago

Description

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

  1. Creating a PrismaClientinstance 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 commented 5 months ago

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

https://github.com/prisma/react-native-prisma/blob/9fce36198f53f4b4f8cfa4236fe90560c2c33ac2/src/index.ts#L19-L25

sorenbs commented 5 months ago

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 commented 5 months ago

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

sorenbs commented 5 months ago

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 commented 4 months ago

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

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

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 commented 2 months ago

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

bogdan-arsene commented 1 month ago

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 commented 3 days ago

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.