From b1be06d3f6e7998bb4caf2edd168113bc135a637 Mon Sep 17 00:00:00 2001 From: Sarah Shader Date: Tue, 17 Sep 2024 16:07:51 -0400 Subject: [PATCH] Improve error message on undefined Convex URL (#29916) The current error message isn't very helpful. Usually when folks run into this it's because they don't have `.env.local` properly configured or they're deploying to production and haven't set `CONVEX_DEPLOY_KEY` or overrode the build command. GitOrigin-RevId: 243becb24ca0771df7b5c06ab5c2083381cd8341 --- src/react/client.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/react/client.ts b/src/react/client.ts index 79a3b01..737aef7 100644 --- a/src/react/client.ts +++ b/src/react/client.ts @@ -240,9 +240,16 @@ export class ConvexReactClient { constructor(address: string, options?: ConvexReactClientOptions) { // Validate address immediately since validation by the lazily-instantiated // internal client does not occur synchronously. + if (address === undefined) { + throw new Error( + "No address provided to ConvexReactClient.\n" + + "If trying to deploy to production, make sure to follow all the instructions found at https://docs.convex.dev/production/hosting/\n" + + "If running locally, make sure to run `convex dev` and ensure the .env.local file is populated.", + ); + } if (typeof address !== "string") { throw new Error( - "ConvexReactClient requires a URL like 'https://happy-otter-123.convex.cloud'.", + `ConvexReactClient requires a URL like 'https://happy-otter-123.convex.cloud', received something of type ${typeof address} instead.`, ); } if (!address.includes("://")) {