diesel
diesel•5w ago

Issue with Clerk Setup With Convex

I set up Clerk and Convex via the docs, but get this error in my dev console (it doesnt work in a production build either) Am I missing an environment variable or something? If I remove the ConvexClientProvider there is no issue. The Clerk Authentication works as intended...
25 Replies
erquhart
erquhart•5w ago
Can you share the file with ConvexClientProvider
diesel
dieselOP•5w ago
'use client' import { ReactNode } from 'react' import { ConvexReactClient } from 'convex/react' import { ConvexProviderWithClerk } from 'convex/react-clerk' import { useAuth } from '@clerk/nextjs' if (!process.env.NEXT_PUBLIC_CONVEX_URL) { throw new Error('Missing NEXT_PUBLIC_CONVEX_URL in your .env file') } const convex = new ConvexReactClient(process.env.NEXT_PUBLIC_CONVEX_URL) export default function ConvexClientProvider({ children }: { children: ReactNode }) { const auth = useAuth(); return ( <ConvexProviderWithClerk client={convex} useAuth={() => auth}> {children} </ConvexProviderWithClerk> ) } And here is my layout.tsx tsx import type { Metadata } from "next"; import localFont from "next/font/local"; import { ClerkProvider } from '@clerk/nextjs' import ConvexClientProvider from '@/components/ConvexClientProvider'; import "./globals.css"; const geistSans = localFont({ src: "./fonts/GeistVF.woff", variable: "--font-geist-sans", weight: "100 900", }); const geistMono = localFont({ src: "./fonts/GeistMonoVF.woff", variable: "--font-geist-mono", weight: "100 900", }); export const metadata: Metadata = { title: "Contests Platform", description: "Custom sports contests platform for companies", }; export default function RootLayout({ children, }: Readonly<{ children: React.ReactNode; }>) { return ( <html lang="en"> <body className={${geistSans.variable} ${geistMono.variable} antialiased} > <ClerkProvider dynamic> <ConvexClientProvider> {children} </ConvexClientProvider> </ClerkProvider> </body> </html> ); }
erquhart
erquhart•5w ago
Maybe your path alias works for TypeScript but not at runtime and ConvexClientProvider is actually undefined in layout.tsx
diesel
dieselOP•5w ago
So how can I fix that? it seems something like that is the issue since it is saying it cannot find the right class based on the name
erquhart
erquhart•5w ago
It's saying ConvexClientProvider == undefined looking at how nextjs path alias is defined Can you share your tsconfig.json
diesel
dieselOP•5w ago
{ "compilerOptions": { "lib": ["dom", "dom.iterable", "esnext"], "allowJs": true, "skipLibCheck": true, "strict": true, "noEmit": true, "esModuleInterop": true, "module": "esnext", "moduleResolution": "bundler", "resolveJsonModule": true, "isolatedModules": true, "jsx": "preserve", "incremental": true, "plugins": [ { "name": "next" } ], "paths": { "@/*": ["./src/*"] } }, "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"], "exclude": ["node_modules"] }
erquhart
erquhart•5w ago
Can you try just using a relative import instead of the path alias
diesel
dieselOP•5w ago
I cleared the .next cache and restarted that didn't fix I copied the examples exactly, so i am not sure why this is an issue
erquhart
erquhart•5w ago
Can you try just using a relative import instead of the path alias The point here is determining what the issue is
diesel
dieselOP•5w ago
I did that and it didn't work
erquhart
erquhart•5w ago
Next step is, while importing via relative path, log the imported component. Can you share the import/log code and the output?
diesel
dieselOP•5w ago
import type { Metadata } from "next"; import localFont from "next/font/local"; import { ClerkProvider } from '@clerk/nextjs' import ConvexClientProvider from '../components/ConvexClientProvider'; import "./globals.css"; const geistSans = localFont({ src: "./fonts/GeistVF.woff", variable: "--font-geist-sans", weight: "100 900", }); const geistMono = localFont({ src: "./fonts/GeistMonoVF.woff", variable: "--font-geist-mono", weight: "100 900", }); export const metadata: Metadata = { title: "Contests Platform", description: "Custom sports contests platform for companies", }; console.log(ConvexClientProvider); export default function RootLayout({ children, }: Readonly<{ children: React.ReactNode; }>) { return ( <html lang="en"> <body className={${geistSans.variable} ${geistMono.variable} antialiased} > <ClerkProvider dynamic> <ConvexClientProvider> {children} </ConvexClientProvider> </ClerkProvider> </body> </html> ); }
No description
diesel
dieselOP•5w ago
The output of the log statement is {}
erquhart
erquhart•5w ago
Well it's clearly not undefined, so that's weird
diesel
dieselOP•5w ago
yeah when i print the clerkprovider, it is an AsyncFunction
erquhart
erquhart•5w ago
What happens if you drop ClerkProvider I know it'll cause things to break further down the tree, but I'm curious if the error about ConvexClientProvider goes away I also wonder if maybe the dynamic rendering on the ClerkProvider isn't playing nice with the client provider
diesel
dieselOP•5w ago
The error still persists when I remove the ClerkProvider Like at this point to I just drop clerk? I like using clerk and this is the first time using convex, so annoying that there is this hiccup
erquhart
erquhart•5w ago
If you dropped the clerk provider and it's still happening I'm not sure Clerk is the problem Is this a project you just started, like something you could put up as a public repo so I can take a look?
diesel
dieselOP•5w ago
Its in a monorepo that's private, I could copy the code to a public repo quick give me 2 mins
erquhart
erquhart•5w ago
Yeah if you can provide a minimal repro I'll take a look
diesel
dieselOP•5w ago
I don't want to include my keys for convex or clerk and you can still take a look?
diesel
dieselOP•5w ago
GitHub
GitHub - DylanZeller/test-contests
Contribute to DylanZeller/test-contests development by creating an account on GitHub.
diesel
dieselOP•4w ago
@erquhart Did you figure this out by chance? it is still a huge issue for me i figured out how to fix it: // Dynamically import ConvexClientProvider to ensure it is only rendered on the client side const ConvexClientProvider = dynamic( () => import("../components/ConvexClientProvider"), { ssr: false } ); makes sure the convexclientprovider is dynamic and only tries to render in client side
erquhart
erquhart•4w ago
I completely missed your response with the repo 🤦‍♂️ sorry about that. I haven’t heard of someone needing to do this before! Glad it’s working for you though. Need to take at look at some point to understand what happened here.
diesel
dieselOP•4w ago
No problem, when you get around to it let me know if there’s anything else you need from me

Did you find this page helpful?