prisma / react-native-prisma

Apache License 2.0
200 stars 9 forks source link

Error: 🟥 @prisma/react-native failed to initialize #39

Open xavier-brandares opened 1 month ago

xavier-brandares commented 1 month ago

I'm on the latest build as of September 28, 2024

I'm getting the Error:

Error: 🟥 @prisma/react-native failed to initialize

Here are the steps I've taken and how I built the project:

Firstly, I've made the expo project:

npx create-expo-app@latest

Then I cd into the project and install the dependencies:

npm install

Then I connected the expo app to the expo go dashboard:

eas init --id <id_string>

Then I run the app on the ios simulator:

npx expo start --ios

Everything is good and works, so I go ahead and install prisma:

npm i --save --save-exact @prisma/client@latest @prisma/react-native@latest react-native-quick-base64

then I modify the app.json plugin section as follow:

{
  "expo": {
    // ... The rest of your expo config
    "plugins": ["@prisma/react-native"]
  }
}

Then I run the following:

npx expo prebuild --clean

Then I initialize prisma

npx prisma init

Then I edit the schema with the following models:

generator client {
  provider = "prisma-client-js"
  previewFeatures = ["reactNative"]
}

datasource db {
  provider = "sqlite"
  url      = "file:./app.db"
}

// Your data model

model User {
  id           Int     @id @default(autoincrement())
  name         String
}

Then I run a migration:

npx prisma@latest migrate dev

Then I generate prisma:

npx prisma@latest generate

Then I make a db.ts file to use reactive queries:

import { PrismaClient } from '@prisma/client/react-native';
import { reactiveHooksExtension } from '@prisma/react-native';

const baseClient = new PrismaClient();

export const extendedClient = baseClient.$extends(reactiveHooksExtension());

Then I modify my component to use prisma:

import { Text } from 'react-native';
import { extendedClient } from './myDbModule';

export default function App {

  // Will automatically re-render the component with new data
  const users = extendedClient.user.useFindMany();

  return (
    <Text>{ users }</Text>
  )
}

Then I restart the app:

npx expo start --ios

Then I get this error:

Simulator Screenshot - iPhone 16 Plus - 2024-09-28 at 09 27 28

xavier-brandares commented 1 month ago

Related issue 23 is still open and has not been resolved.

I use prisma for NextJS and it works flawlessly, sucks that this issue completely hard locks the package.

t0piCyb commented 4 weeks ago

I've got the same problem just for android, it's ok for ios but android throws this error

piscopancer commented 1 week ago

you may have messed the order of commands or after generating native code try running your app with expo start --dev-client command on your emulator, it works for me

Prathamesh01110 commented 1 week ago

@piscopancer i tried doing it but it didn't worked too i did cd android and ./gradlew clean and then npx expo start --dev-client still got the same error

i will get you the exact code(by making you collaborator for private repo) will you try to run and fix and tell me the problem

abc-tiago commented 3 hours ago

I've tried everything and mine always gives the same error. I'm trying to use expo 52 react native 0.76 and the version is recent from react-native-prisma

`> Task :prisma_react-native:configureCMakeDebug[arm64-v8a] FAILED

FAILURE: Build failed with an exception.