prisma / react-native-prisma

Apache License 2.0
180 stars 7 forks source link

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

Open xavier-brandares opened 1 week ago

xavier-brandares commented 1 week 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 week 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.