Error: this method must be invoked in a node.js environment
I'm using Kind with NextJs, and everything was working well, but out of nowhere, I've started to get the following error:
Unhandled Runtime Error
Error: this method must be invoked in a node.js environment
Call Stack
createKindeServerClient
node_modules/.pnpm/@[email protected]/node_modules/@kinde-oss/kinde-typescript-sdk/dist/sdk/clients/server/index.js (7:0)
I've installed the NextJS App Router SDK v2.
3 Replies
Hi @Ruben Silva,
It seems like you're trying to use a server-side method in a client-side environment. The
createKindeServerClient
method is meant to be used in a server-side environment like Next.js API routes or getServerSideProps.
If you're trying to use it in a client-side component, it won't work and will throw the error you're seeing. Instead, you should use client-side methods provided by the SDK in your components.
For example, if you're trying to fetch user data, you can use the useUser
hook in your component like this:
If you need to use server-side methods, make sure to use them in the appropriate server-side contexts like API routes or getServerSideProps. For example:
I hope this helps! Let me know if you have any other questions.Thank you for the response. I was experimenting with rendering server components inside client components, and that's where the error could be occurring.
I was experimenting with rendering server components inside client components, and that's where the error could be occurring.Understood. Well please reach out if you come across anymore issues.