Shyam sai teja
Shyam sai teja•2mo ago

How to fetch data in Nextjs SSC using Convex ?

please help me solve the following error when attempting to fetch data in SSC using fetchQuery or any other functions. It is throwing me the following error, shown in the image. I tried to go through the Convex docs and other resources provided by Convex https://github.com/get-convex/template-nextjs/blob/main/app/server/page.tsx example preloaded Functions, and tried to change the provider configuration also, but it was of no use please help me resolve how to fetch Convex data in SSC
GitHub
template-nextjs/app/server/page.tsx at main · get-convex/template-...
Contribute to get-convex/template-nextjs development by creating an account on GitHub.
No description
52 Replies
Shyam sai teja
Shyam sai tejaOP•2mo ago
@moderators please help me in resolving the issue
Sara
Sara•2mo ago
Do not ping mods for support tickets, the ping is to help catch spammers, be patient you'll get someone replying to your thread soon! @Shyam sai teja SO, Looking at the code here, this seems to be a problem with clerk which you haven't sent the code for, I ran the template and its working fine for me, can you share the snippit that actually caused this error to happen? and make sure that: - You have ran pnpm i/ npm i - ran pnpm dlx convex dev and made sure that the project is setup correctly on your end - you updated your enviroment variables to match the client and convex's deployment Please ask better questions next time, help us to help you 😅
Shyam sai teja
Shyam sai tejaOP•2mo ago
ok, it's not about the template; the template will run fine. Can you please run the following repo and figure out the issue https://github.com/Shyamsaitejamandibi/clone-t3 The issue is coming with this repo if I try to use preload or fetchquery, and for more information, I can share the terminal error, as one example is [cause]: [AggregateError: ] { code: 'ETIMEDOUT' } in convex. If you want env variables, I can provide them if you dm me
GitHub
GitHub - Shyamsaitejamandibi/clone-t3
Contribute to Shyamsaitejamandibi/clone-t3 development by creating an account on GitHub.
Sara
Sara•2mo ago
nope, sorry can't do. please share the minimalist code snippit that caused the problem or share the code lines from that repo
Shyam sai teja
Shyam sai tejaOP•2mo ago
ok ill prepare a template where it will cause an error using in SSC and send it to you. Please give me some time, Sara
Sara
Sara•2mo ago
Kindly share it here. do not DM me
Shyam sai teja
Shyam sai tejaOP•2mo ago
ok, sure, can I mention you will return?
Sara
Sara•2mo ago
no, cause I will check it when I can!
Shyam sai teja
Shyam sai tejaOP•2mo ago
ok thank you
Shyam sai teja
Shyam sai tejaOP•2mo ago
Sara, during the replication of the error, I tried to run the template first so I could make some changes on top, making your process easier. However, the template itself is throwing an error for me. Can you please debug it for me? Terminal error: ⨯ TypeError: fetch failed at async ServerPage (app\server\page.tsx:6:20) 4 | 5 | export default async function ServerPage() {
6 | const preloaded = await preloadQuery(api.myFunctions.listNumbers, {
| ^ 7 | count: 3, 8 | }); 9 | { digest: '640672731', [cause]: [AggregateError: ] { code: 'ETIMEDOUT' } } GET /server 500 in 6471ms
No description
Shyam sai teja
Shyam sai tejaOP•2mo ago
Hey Sara, please check it out
Sara
Sara•2mo ago
Have you made sure that you're running pnpm dlx convex dev? Cause to me this looks like an error of not having the functions configured
Shyam sai teja
Shyam sai tejaOP•2mo ago
Yes, I'm running it, and it's not throwing any errors in the functions, also it is not calling any function at first place
No description
Sara
Sara•2mo ago
Do you see the functions in the dashboard? And the logs Oh wait Yeah i know the problem It looks like you have misunderstood how these functions work, move line 10 down the tree to a client component and pass the propa of the preloaded query to it, the error is happening because the async fetch hasn't finished when the second sync function was called Also, as far as i can tell you might be using the wrong function, use usePreloadedQuery on the client side instead
Shyam sai teja
Shyam sai tejaOP•2mo ago
It is the same template provided by Convex(https://github.com/get-convex/template-nextjs). I haven't changed one line of code so can you please tell me where exactly the problem is
Sara
Sara•2mo ago
Your problem is a client side issue as you can tell, so like i said before make sure that everything is updating correctly on your dashboard My hands are tied I'd comment out things to debug, from there you can figure out what's going on One more questions, what are the 6 changes you've done on this repo?
Shyam sai teja
Shyam sai tejaOP•2mo ago
Yes functions and schema are in sync with the dashboard, but there are no logs in the dashboard because, by using these preload functions, they are throwing errors from the client side before the functions are called
Sara
Sara•2mo ago
Do you have them in the convex folder?
Shyam sai teja
Shyam sai tejaOP•2mo ago
they are _generated folder from convex yes
Sara
Sara•2mo ago
Hmm, could you send the serverPage component in a code block? Wrapped around ``` ```
Shyam sai teja
Shyam sai tejaOP•2mo ago
import Home from "./inner";
import { preloadQuery, preloadedQueryResult } from "convex/nextjs";
import { api } from "@/convex/_generated/api";

export default async function ServerPage() {
const preloaded = await preloadQuery(api.myFunctions.listNumbers, {
count: 3,
});

const data = preloadedQueryResult(preloaded);

return (
<main className="p-8 flex flex-col gap-4 mx-auto max-w-2xl">
<h1 className="text-4xl font-bold text-center">Convex + Next.js</h1>
<div className="flex flex-col gap-4 bg-slate-200 dark:bg-slate-800 p-4 rounded-md">
<h2 className="text-xl font-bold">Non-reactive server-loaded data</h2>
<code>
<pre>{JSON.stringify(data, null, 2)}</pre>
</code>
</div>
<Home preloaded={preloaded} />
</main>
);
}
import Home from "./inner";
import { preloadQuery, preloadedQueryResult } from "convex/nextjs";
import { api } from "@/convex/_generated/api";

export default async function ServerPage() {
const preloaded = await preloadQuery(api.myFunctions.listNumbers, {
count: 3,
});

const data = preloadedQueryResult(preloaded);

return (
<main className="p-8 flex flex-col gap-4 mx-auto max-w-2xl">
<h1 className="text-4xl font-bold text-center">Convex + Next.js</h1>
<div className="flex flex-col gap-4 bg-slate-200 dark:bg-slate-800 p-4 rounded-md">
<h2 className="text-xl font-bold">Non-reactive server-loaded data</h2>
<code>
<pre>{JSON.stringify(data, null, 2)}</pre>
</code>
</div>
<Home preloaded={preloaded} />
</main>
);
}
Sara
Sara•2mo ago
That's odd I'd check the node version on your machine Run node -v
Shyam sai teja
Shyam sai tejaOP•2mo ago
Sara, only _generated folder is what got added by running npx convex a, that's all, no changes from the template I've done, and I've gone through the convex docs also, and there was no single discussion I'm able to find regarding this error v24.0.1
Sara
Sara•2mo ago
Like I suspected, this is a node issue https://github.com/nodejs/undici/issues/2777
GitHub
fetch fail: cause: AggregateError [ETIMEDOUT]: · Issue #2777 · no...
Bug Description my code is typescript. I run it in two ways: use bun compile to js, and use node v21 when use bun run it, no error occurs; when use node run it, it occurs fetch failed extremely fre...
Shyam sai teja
Shyam sai tejaOP•2mo ago
what is the solution ?
Sara
Sara•2mo ago
soooo I'd start by downgrading to node22, then I'd remove node_modules, then I'd remove the _generated folder (while having the server fully off) then I'd run npm i , npm dev, this should run both frontend and backend If this didn't work, I'll have to ask you to use pnpm 😂 , npm is known for so many issues like keeping every instance of node_modules on your device (this is not the issue, just making a tiny joke)
Shyam sai teja
Shyam sai tejaOP•2mo ago
ohh the problem is with pnpm also sorry to mention it late
Sara
Sara•2mo ago
yeah then its something to do with your node version I'd delete the folders I mentioned above and start over, do not use both npm and pnpm on the same repo. that's gonna cause other issues
Shyam sai teja
Shyam sai tejaOP•2mo ago
ok ill try to proceed with the process you mentioned and try everything possible. If nothing works, I'll get back to you. Thank you here in the thread only ill not dm you or mention you😂
Sara
Sara•2mo ago
thank you!
Shyam sai teja
Shyam sai tejaOP•2mo ago
Sara, no use, tried everything I could, but the error isn't getting resolved Can you please try in your local ? Is it really working? Please check it once, know my node:v22.19.0 npm:10.9.3
Sara
Sara•2mo ago
I've already tried it and it works for me just fine
Shyam sai teja
Shyam sai tejaOP•2mo ago
ok, if it works for you, then the same code when pushing or any other hosting provider should work, know?
Sara
Sara•2mo ago
no, its not like that. its not a convex issue, its something to do with your setup I'd give it another shot with pnpm It might be the issue.
Shyam sai teja
Shyam sai tejaOP•2mo ago
Okay, let's say the issue is with my setup only, but if it is hosted, then the template should work, know? It has nothing to do with my setup, right? It is the code provided by Convex, right? So it should work on Vercel, right? yes tried with pnpm also
Sara
Sara•2mo ago
It is your setup, because it is working on the dashboard (the functions are) but your client is not accepting it. also, what is kinda making suspect it has nothing to do with your convex is the fact that you have 6 changes to the repo when it shouldn't even change anything like at all I'd seriously consider discarding changes or starting fresh
Shyam sai teja
Shyam sai tejaOP•2mo ago
Sara, i didn't manually change anything when I ran npx/pnpm dlx convex dev. The _generated folder is automatically getting modified
Sara
Sara•2mo ago
I'm googling it, give me a sec can you push eveything to github and send a link to the repo please? and could you check if you've hit a limit on convex's functions?
Shyam sai teja
Shyam sai tejaOP•2mo ago
okay give me 2 mins
Shyam sai teja
Shyam sai tejaOP•2mo ago
https://github.com/Shyamsaitejamandibi/convex and hosted, also it is working perfectly fine on vercel so there is an issue with my setup only can you help me to figure it out ?
GitHub
GitHub - Shyamsaitejamandibi/convex
Contribute to Shyamsaitejamandibi/convex development by creating an account on GitHub.
Shyam sai teja
Shyam sai tejaOP•2mo ago
The error it's throwing is also
> 6 | const preloaded = await preloadQuery(api.myFunctions.listNumbers, {
| ^
7 | count: 3,
8 | });
9 | {
digest: '2175136560',
[cause]: [Error [ConnectTimeoutError]: Connect Timeout Error (attempted addresses: 52.54.48.130:443, 2600:1f18:77e:2300:4929:e49b:6cb2:75e6:443, 52.44.230.118:443, 2600:1f18:77e:2302:ddda:86fa:5687:daaa:443, 52.200.179.149:443, 2600:1f18:77e:2301:685b:995f:b5bb:9cbf:443, timeout: 10000ms)] {
code: 'UND_ERR_CONNECT_TIMEOUT'
}
}
> 6 | const preloaded = await preloadQuery(api.myFunctions.listNumbers, {
| ^
7 | count: 3,
8 | });
9 | {
digest: '2175136560',
[cause]: [Error [ConnectTimeoutError]: Connect Timeout Error (attempted addresses: 52.54.48.130:443, 2600:1f18:77e:2300:4929:e49b:6cb2:75e6:443, 52.44.230.118:443, 2600:1f18:77e:2302:ddda:86fa:5687:daaa:443, 52.200.179.149:443, 2600:1f18:77e:2301:685b:995f:b5bb:9cbf:443, timeout: 10000ms)] {
code: 'UND_ERR_CONNECT_TIMEOUT'
}
}
Sara
Sara•2mo ago
yaay that's a new error
Shyam sai teja
Shyam sai tejaOP•2mo ago
🙃 in just an instant i has worked in local and throwed this error
Sara
Sara•2mo ago
could you please check if those variables are inside your .local.env?
# Deployment used by `npx convex dev`
CONVEX_DEPLOYMENT=

NEXT_PUBLIC_CONVEX_URL=
# Deployment used by `npx convex dev`
CONVEX_DEPLOYMENT=

NEXT_PUBLIC_CONVEX_URL=
that's good. that's really good I finally am able to reproduce it. check your enviroment variables
Shyam sai teja
Shyam sai tejaOP•2mo ago
yes 🙂 im not that dumb
Sara
Sara•2mo ago
I'm not saying you're. I'm saying check. because I was just able to reproduce it by adding a coma to my link
Sara
Sara•2mo ago
No description
Sara
Sara•2mo ago
remove the / for crying out loud.
Shyam sai teja
Shyam sai tejaOP•2mo ago
ill delete it any how they are testing purpose no issue
Sara
Sara•2mo ago
"/" remove it. so its a URL not a route. I'm sorry but we've got to lock this post. the issue is considered resolved from this point. everyone's getting pinged and its not a work day for people. anything else, pleasse make a new post.
Shyam sai teja
Shyam sai tejaOP•2mo ago
sara that wasnt the issue please help i'm totally stuck if that was the then why will other page (home page) work ? the function calls were all nicely working in home page jamie did you get context of my error(this thread) ?
jamwt
jamwt•2mo ago
locking this post. we love to be helpful to developers, but this is above and beyond for community support. please create a pro support ticket in your dashboard and we can attempt to help there

Did you find this page helpful?