Next.js Discord

Discord Forum

Build Time Pre Render Error

Answered
rkstlohchab posted this in #help-forum
Open in Discord
@"use php"
Im getting prebuild error

398 Replies

@rkstlohchab <@755810867878297610> Im getting prebuild error
Does it work fine with npm run Dev?
yes
it is working fine with run dev
i think the problem is that i am not using async await for data
or is it something else
Can you send full error like also above
@rkstlohchab <@755810867878297610> Im getting prebuild error
dont put your logic inside your page.tsx
if this is rsc try forcing that route to dynamic rendering
could be that on build time your api is not accessible
@gin if this is rsc try forcing that route to dynamic rendering
can u suggest some docs about it
Answer
export const dynamic = 'force-dynamic'
put this in your page.tsx
@"use php" Can you send full error like also above
@"use php"
@"use php" your next version?
14.2.7
let me try
@"use php" can u tell exactly what to write here i tried but its not working
"use client";

export default function Page() {
  // Fetch the list of expertise entries
  const blogList = useQuery(api.blog.getBlog);
  const router = useRouter();

  if (!blogList) {
    return <Loader />;
  }

  const handleCardClick = (blogId: string) => {
    router.push(`/blog/${blogId}`);
  };

  return (
    <div className="lg:px-[120px] lg:py-[30px] max-sm:px-10 max-sm:py-5">
      <h1 className="w-full text-start text-2xl my-5">Our Expertise</h1>
      <p>
        Our main goal is to make a real difference by adding value to society.


      </p>
      <Separator className="my-5" />

      <AccordinMy />

      <Separator className="my-5" />

      {blogList?.map((blog) => (
        <Card 
          key={blog._id} 
          className=" m-0 p-0 border-none shadow-none inline-block "
          onClick={() => handleCardClick(blog._id)}
        >
            <CardHeader className="gap-2 lg:mr-10 lg:my-10 max-sm:mt-8">
                <Image src={blog.image} alt="abc" width={350} height={210} className="w-[350px] h-[210px]"/>
                <CardTitle className="font-normal">{blog.title}</CardTitle>
                <CardDescription className="">{blog.description.split(' ').slice(0, 3).join(' ')}</CardDescription>
            </CardHeader>
        </Card>
        ))}
    </div>
  );
}
can you send your page.tsx file?
"use client"

import Blog from "@/components/blog"
import Footer from "@/components/Footer"
import Hero from "@/components/Hero"
import Loader from "@/components/Loader"
import SecondSec from "@/components/SecondSec"
import ThirdSec from "@/components/ThirdSec"
import { Separator } from "@/components/ui/separator"
import { useState, useEffect } from "react"


const Page = () => {

  const [isLoading, setIsLoading] = useState(true);

    useEffect(() => {
      const timer = setTimeout(() => {
        setIsLoading(false);
      }, 3000);

      return () => clearTimeout(timer);
    }, []);
  
    if(isLoading) {
      return <Loader />
    }

  return (
    <div className="">
      <Hero />
      <SecondSec />
      <ThirdSec />
      <Separator className="my-10" />
      <Blog />
      <Footer />
    </div>
  )
@"use php" Imports?
let me send
"use client";

import { useQuery, useMutation } from "convex/react";
import { api } from "@/../convex/_generated/api";
import { Id } from "../../../convex/_generated/dataModel";
import Image from "next/image";
import { useRouter } from "next/navigation";
import { Separator } from "@/components/ui/separator";

import {
  Card,
  CardContent,
  CardDescription,
  CardFooter,
  CardHeader,
  CardTitle,
} from "@/components/ui/card";
import Loader from "@/components/Loader";
import AccordinMy from "@/components/expertiseAccordin";
can you remove useQuery, and see if the build works?
why would this be issue
do the thing i told u
@gin this is your page.tsx
this is my expertise.tsx
@gin then u can export dynamic
i didnt understood how to use dynamic
@rkstlohchab this is my expertise.tsx
why is it called Page xD
show me your page.tsx
where the error occurs
@gin why is it called Page xD
bcoz its app router
this is your page.tsx
??
do this
bcoz the convex wont work
@gin Click to see attachment
okay
is useQuery a client or a server library?
if it a server library, then yes, he's right
@"use php" is useQuery a client or a server library?
it is convex backend as a service syntax
for retreiving data from db
just like mongo
Then yes, he's right
@rkstlohchab Click to see attachment
removed use client from the file
now useRouter is casuing error
bcoz it need use client
tried removing use client from the blog page.tsx
@"use php"
@rkstlohchab removed use client from the file
Put it in a different file
bro put what in diff file ?
use client ?
@rkstlohchab Click to see attachment
how can i put this in other file
should i give u live share link?
@"use php"
Umm, no, My wifi is currently down, and I'm on mobile data, so can't
Create a client file, which accepts blogPosts
in page.tsx, fetch the data using await, and use the client component and pass it there
@"use php" Create a client file, which accepts blogPosts
like this?
you got it right, now move the useQuery to the page.tsx
and pass it
accept a prop blogPosts on page
@"use php" and pass it
pass it to?
client component
blog componnet?
okay
@"use php" client component
?like this
now the blog will render and other will cause error right?
Its props, so you need to add a curcly brances around blogPost
you should be good to go then
@"use php" you should be good to go then
let me check
and you can directly return the loader in the page.tsx ig
@"use php"
check what?
oh
didn't notice
await it maybe
if its needed to await, await it
:lolsob:
does it work on dev?
@"use php" does it work on dev?
it does perfectly
I'm not familiar much with convex, like I've never used it. So I don't think I can help. You can try stackoverflow, or wait for a response from someone with experience with convex
if you can, try to replace useContext with some static data
for sake of testing
i dont know bro what to do now
i have to deliver the website tomorrow
@"use php" @gin
@rkstlohchab whats your anydesk
code
wait
@gin
i have
more optimal way
Wait I don't really recommend anydesk
use codeshare
vscode share
@rkstlohchab
yeah its laggy
@gin let me give you live share
@gin
try to build
@rkstlohchab
u have to build
im in browser
wait
nicee
expertise is fixed
@gin n
now
other routes left
ill do that
wait
just keep my website structure intact brother okay
try to build
@rkstlohchab
wait @gin
@gin thanks a lot brother
can u tell what did u do exactly
wait is it fixed?
i see errors
yea
check
nice
ah wait
check this
@gin
can u start a new terminal
sure
done
whats the error?
just this
can u reload the page
f5
wait
done
reload now
everything seems to be working
but why terminal is showing error?
@gin and can u also sum of what u did
everything good in terminal now too
still showing error?
@gin still showing error?
nope
working
ok good
again @gin
are u reloading the page?
reload and go to /expertise
@gin are u reloading the page?
i am
ok wait
let me debug
dont switch routes
and bro
one thing
the loader component is neccessary while loading website
@gin its avail on every page but homepage is not showing
only homepage?
go on /expertise
yepp
@gin
convex provider is imp
thats not /expertise
thats home
localhost/expertise
alr
dont switch
is expertise working?
reload
yes
its working
now go to home
wokring
wait
but
/500 and loader issue
are u on home
reload
@gin are u on home
yes
done
still same
btw
if 500 is showing why the website is not crashing @gin
fixed? @rkstlohchab
no @gin
website id able to load data
but terminal is showing 500
why so ?
and loader not showing on homepage
showing now?
no
now?
try home now
go on /
not showing
now?
no
is the spinner here text showing
not
showing
every route showing not on homepage
i found the issue i think
its because of your loader
wait let me reverse
okyy
switch routes
i did
about and homepage
are not able to render
loader
can u swtich around
expertise project blog
are rendering
loader
no issues right and u see the "123" on every page where the loader is
i see 123
ok good
and
how does your loader look like
@rkstlohchab Click to see attachment
this is projects
is it this?
no
straight line
@gin maybe
u are not
using loader on
homepage
do u see the alert
i do
on home
ok wait
hello?!
@gin on home
no
wait a sec
what do u see now
on other pages
i cant upload more image
server is not allowing
is it fixed
can u just make everything back to normal let me try
@gin is it fixed
it is on /expertise
and
/
/about
on home?
shows
no loader
did u even use loader on homepage im asking?
like u did on /expertise /project
yeah
/about
check this page
there is no loader in about
okay
cool so its fixed
the issue was the library u was using for the loader
i looked at their docs and just used the css version
oh ohkay
terminal is okay too
but
homepage is still not showing loader
whats the reason
for that
uhh
for the loader not showing in /?
yeaaa
thats what im
tryint to tell
@gin
i found the issue
check now
not working yet /
@gin
i think
u are
trying
to load the loader in
blog.tsx
but that file is for only /blog
it wont render loader on /
wait are u rendering the same thing in /blog
are u trying to render the content from blog in home
aswell?
yeaaa
ahhhhhhhhhhhhhhhhhhh
i made a
blog
yes wait
component
and
i am rendering it on
/
/expertise
and /blogs too
btw
u just copied the client code in component and rendered it on page.tsx of routes right
that solved the build issue? @gin
yeah
they were two issues
one with your loader and the other with prerendering
okayy
soo everything fixed
yep
ill take care of the
loader on
/
and
at last
let me run
build
@gin
alr go on
@gin
show me your project root
on my side i only have one blog
wait
one is route
one is component
done
did u delete blog.tsx
the one with lowercase
just let me add loader on homepage
nope
i did nothing
while u was working
let me add loader on homepage first
then ill text you
it is already added
the issue is that vscode is bugging
oh okay
in your
it is telling that there is two blog.tsx but one with Uppercase
pc
is it showing
let me clear cache
approve
done
now build
working
close your devserver
and do npm run start
and check if the loader is
there
wait
u have a devserver running aswell
u should close that when u are building
thats your devserver
close it
and build again
now build
and npm run start
working
also the loader?
not the loader
thats okay
ill take care of it
alr
yep
u can mark my answer as solution
for the prerender
sure
thanks!