Skip to content

feat: show actionable resolutions for native module initialization errors #20

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 36 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -13,6 +13,29 @@ declare global {
var __PrismaProxy: PrismaProxy | undefined;
}

const errorResolutions = [
`1. Ensure @prisma/react-native is added to the plugins section in app.json`,

`2. Ensure at least one migration exists:

$ prisma migrate dev`,

`3. Try removing the node_modules/ folder and running the prebuild command:

$ rm -rf node_modules/
$ npx expo prebuild --clean
`,
`4. If in a monorepo, ensure the application's package.json also has the required Prisma dependencies:

$ npm i @prisma/client@latest @prisma/react-native@latest react-native-quick-base64
$ yarn add @prisma/client@latest @prisma/react-native@latest react-native-quick-base64
`,
];

const makeErrorMessage = (message: string) => {
return [message, errorResolutions.join('\n\n')].join('\n\n');
};

// @ts-expect-error
const isTurboModuleEnabled = global.__turboModuleProxy != null;

@@ -21,13 +44,23 @@ const PrismaModule = isTurboModuleEnabled
: NativeModules.Prisma;

if (!PrismaModule) {
throw new Error('🟥 @prisma/react-native failed to initialize');
throw new Error(
makeErrorMessage('🟥 @prisma/react-native failed to initialize')
);
}

PrismaModule.install();
try {
PrismaModule.install();
} catch {
throw new Error(
makeErrorMessage(`🟥 @prisma/react-native failed to install`)
);
}

if (!global.__PrismaProxy) {
throw new Error('🟥 prisma/react-native C++ bindings failed to initialize');
throw new Error(
makeErrorMessage('🟥 prisma/react-native C++ bindings failed to initialize')
);
}

// Wrap the create function to stringify the env variables if necessary

Unchanged files with check annotations Beta

import fs from 'node:fs/promises';
import path from 'node:path';
import { $ } from 'zx';

Check warning on line 3 in scripts/bump-client.ts

GitHub Actions / Run test / Lint

There should be at least one empty line between import groups
import { downloadEngine, ensureNpmTag, writeVersionFile } from './utils';
async function main() {
client: {
$refreshSubscriptions: async () => {
await refreshSubscriptions();
}

Check warning on line 32 in src/ReactiveHooksExtension.ts

GitHub Actions / Run test / Lint

Insert `,`
},
model: {
$allModels: {
client: {
$refreshSubscriptions: async () => {
await refreshSubscriptions();
}

Check warning on line 31 in src/ReactiveQueriesExtension.ts

GitHub Actions / Run test / Lint

Insert `,`
},
model: {
$allModels: {