Skip to content

Commit

Permalink
Improve error message on undefined Convex URL (#29916)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
sshader authored and Convex, Inc. committed Sep 17, 2024
1 parent e4d807c commit b1be06d
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/react/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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("://")) {
Expand Down

0 comments on commit b1be06d

Please sign in to comment.