Skip to content

Commit 6f2916e

Browse files
committed
feat: show actionable resolutions for native module initialization errors
Show a few common resolutions when the native module fails to initialize for any reason. Partially resolves prisma#16.
1 parent a2f22b1 commit 6f2916e

File tree

1 file changed

+36
-3
lines changed

1 file changed

+36
-3
lines changed

src/index.ts

+36-3
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,29 @@ declare global {
1313
var __PrismaProxy: PrismaProxy | undefined;
1414
}
1515

16+
const errorResolutions = [
17+
`1. Ensure @prisma/react-native is added to the plugins section in app.json`,
18+
19+
`2. Ensure at least one migration exists:
20+
21+
$ prisma migrate dev`,
22+
23+
`3. Try removing the node_modules/ folder and running the prebuild command:
24+
25+
$ rm -rf node_modules/
26+
$ npx expo prebuild --clean
27+
`,
28+
`4. If in a monorepo, ensure the application's package.json also has the required Prisma dependencies:
29+
30+
$ npm i @prisma/client@latest @prisma/react-native@latest react-native-quick-base64
31+
$ yarn add @prisma/client@latest @prisma/react-native@latest react-native-quick-base64
32+
`,
33+
];
34+
35+
const makeErrorMessage = (message: string) => {
36+
return [message, errorResolutions.join('\n\n')].join('\n\n');
37+
};
38+
1639
// @ts-expect-error
1740
const isTurboModuleEnabled = global.__turboModuleProxy != null;
1841

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

2346
if (!PrismaModule) {
24-
throw new Error('🟥 @prisma/react-native failed to initialize');
47+
throw new Error(
48+
makeErrorMessage('🟥 @prisma/react-native failed to initialize')
49+
);
2550
}
2651

27-
PrismaModule.install();
52+
try {
53+
PrismaModule.install();
54+
} catch {
55+
throw new Error(
56+
makeErrorMessage(`🟥 @prisma/react-native failed to install`)
57+
);
58+
}
2859

2960
if (!global.__PrismaProxy) {
30-
throw new Error('🟥 prisma/react-native C++ bindings failed to initialize');
61+
throw new Error(
62+
makeErrorMessage('🟥 prisma/react-native C++ bindings failed to initialize')
63+
);
3164
}
3265

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

0 commit comments

Comments
 (0)