Next.js Discord

Discord Forum

Getting error prerender of /

Answered
Bonga shad posted this in #help-forum
Open in Discord
Bonga shadOP
✓ Compiled successfully
✓ Linting and checking validity of types
✓ Collecting page data
Generating static pages (0/6) [ ][MYSQL] Connected
[MYSQL] Connected
Generating static pages (0/6) [= ]failed to get ticket n [Error]: Dynamic server usage: no-store fetch http://localhost:3000/api/Tickets /
at D:\JS project\Bug_report_forum.next\server\chunks\948.js:2:8547
at D:\JS project\Bug_report_forum.next\server\chunks\948.js:2:15875
at a.with (D:\JS project\Bug_report_forum.next\server\chunks\948.js:1:8878)
at c.with (D:\JS project\Bug_report_forum.next\server\chunks\948.js:1:3078)
at c.startActiveSpan (D:\JS project\Bug_report_forum.next\server\chunks\948.js:1:18133)
at a.startActiveSpan (D:\JS project\Bug_report_forum.next\server\chunks\948.js:1:18667)
at D:\JS project\Bug_report_forum.next\server\chunks\948.js:2:15408
at a.with (D:\JS project\Bug_report_forum.next\server\chunks\948.js:1:8878)
at c.with (D:\JS project\Bug_report_forum.next\server\chunks\948.js:1:3078)
at b.trace (D:\JS project\Bug_report_forum.next\server\chunks\948.js:2:15362) {
description: 'no-store fetch http://localhost:3000/api/Tickets /',
digest: 'DYNAMIC_SERVER_USAGE'
}
failed to get ticket n [Error]: Dynamic server usage: no-store fetch http://localhost:3000/api/Tickets /
at D:\JS project\Bug_report_forum.next\server\chunks\948.js:2:8547
at D:\JS project\Bug_report_forum.next\server\chunks\948.js:2:15875
at a.with (D:\JS project\Bug_report_forum.next\server\chunks\948.js:1:8878)
at c.with (D:\JS project\Bug_report_forum.next\server\chunks\948.js:1:3078)
at c.startActiveSpan (D:\JS project\Bug_report_forum.next\server\chunks\948.js:1:18133)
at a.startActiveSpan (D:\JS project\Bug_report_forum.next\server\chunks\948.js:1:18667)
at D:\JS project\Bug_report_forum.next\server\chunks\948.js:2:15408
at a.with (D:\JS project\Bug_report_forum.next\server\chunks\948.js:1:8878)
at c.with (D:\JS project\Bug_report_forum.next\server\chunks\948.js:1:3078)
at b.trace (D:\JS project\Bug_report_forum.next\server\chunks\948.js:2:15362) {
description: 'no-store fetch http://localhost:3000/api/Tickets /',
digest: 'DYNAMIC_SERVER_USAGE'
}
TypeError: Cannot destructure property 'tickets' of '(intermediate value)' as it is undefined.
at b (D:\JS project\Bug_report_forum.next\server\app\page.js:1:81719)
at processTicksAndRejections (node:internal/process/task_queues:95:5)
at runNextTicks (node:internal/process/task_queues:64:3)
at listOnTimeout (node:internal/timers:540:9)
at process.processTimers (node:internal/timers:514:7) {
digest: '3148590653'
}
Generating static pages (2/6) [== ]TypeError: Cannot destructure property 'tickets' of '(intermediate value)' as it is undefined.
at b (D:\JS project\Bug_report_forum.next\server\app\page.js:1:81719) {
digest: '3435398082'
}
TypeError: Cannot destructure property 'tickets' of '(intermediate value)' as it is undefined.
at b (D:\JS project\Bug_report_forum.next\server\app\page.js:1:81719) {
digest: '3435398082'
}

Error occurred prerendering page "/". Read more: https://nextjs.org/docs/messages/prerender-error

TypeError: Cannot destructure property 'tickets' of '(intermediate value)' as it is undefined.
at b (D:\JS project\Bug_report_forum.next\server\app\page.js:1:81719)
at processTicksAndRejections (node:internal/process/task_queues:95:5)
at runNextTicks (node:internal/process/task_queues:64:3)
at listOnTimeout (node:internal/timers:540:9)
at process.processTimers (node:internal/timers:514:7)
✓ Generating static pages (6/6)

Export encountered errors on following paths:
/page: /
Answered by Anay-208
You can’t use static export
View full answer

145 Replies

Bonga shadOP
What's wrong so?
Some codem
@Clown Some codem
Bonga shadOP
?
How are you fetching this?
Send the code in a code block here
@Clown Send the code in a code block here
Bonga shadOP
of which file?
The part where you are fetching the Ticket api endpoint
@Clown The part where you are fetching the `Ticket` api endpoint
Bonga shadOP
import TicketCard from "./(components)/TicketCard"

const getTickets = async () => {
  try {
    const res = await fetch("http://localhost:3000/api/Tickets", {
      cache: "no-store"
    })

    return res.json();
  } catch (error) {

    console.log('failed to get ticket', error)
  }
}

const Dashboard = async () => {

  const { tickets } = await getTickets();
  console.log(tickets)
  const uniqueCategories = [
    ... new Set(tickets?.map(({ Project }) => Project)),
  ];

  console.log(uniqueCategories)

  return (
    <div className="p-5">
      <div>
        {tickets && uniqueCategories?.map((uniqueCategory, categoryIndex) => (
          <div key={categoryIndex} className="mb-4">
            <h2>{uniqueCategory}</h2>
            <div className="lg:grid grid-cols-2 xl:grid-cols-4">

              {tickets.filter((ticket) => ticket.Project === uniqueCategory).map((filteredTicket, _index) => (
                <TicketCard id={_index} key={_index} ticket={filteredTicket} />
              ))}
            </div>
          </div>
        ))}

      </div>
    </div>
  )
}
export default Dashboard
That try catch is most likely causing the error
@Clown That try catch is most likely causing the error
Bonga shadOP
so i need to remove try catch block?
@Bonga shad ✓ Compiled successfully ✓ Linting and checking validity of types ✓ Collecting page data Generating static pages (0/6) [ ][MYSQL] Connected [MYSQL] Connected Generating static pages (0/6) [= ]failed to get ticket n [Error]: Dynamic server usage: no-store fetch http://localhost:3000/api/Tickets / at D:\JS project\Bug_report_forum\.next\server\chunks\948.js:2:8547 at D:\JS project\Bug_report_forum\.next\server\chunks\948.js:2:15875 at a.with (D:\JS project\Bug_report_forum\.next\server\chunks\948.js:1:8878) at c.with (D:\JS project\Bug_report_forum\.next\server\chunks\948.js:1:3078) at c.startActiveSpan (D:\JS project\Bug_report_forum\.next\server\chunks\948.js:1:18133) at a.startActiveSpan (D:\JS project\Bug_report_forum\.next\server\chunks\948.js:1:18667) at D:\JS project\Bug_report_forum\.next\server\chunks\948.js:2:15408 at a.with (D:\JS project\Bug_report_forum\.next\server\chunks\948.js:1:8878) at c.with (D:\JS project\Bug_report_forum\.next\server\chunks\948.js:1:3078) at b.trace (D:\JS project\Bug_report_forum\.next\server\chunks\948.js:2:15362) { description: 'no-store fetch http://localhost:3000/api/Tickets /', digest: 'DYNAMIC_SERVER_USAGE' } failed to get ticket n [Error]: Dynamic server usage: no-store fetch http://localhost:3000/api/Tickets / at D:\JS project\Bug_report_forum\.next\server\chunks\948.js:2:8547 at D:\JS project\Bug_report_forum\.next\server\chunks\948.js:2:15875 at a.with (D:\JS project\Bug_report_forum\.next\server\chunks\948.js:1:8878) at c.with (D:\JS project\Bug_report_forum\.next\server\chunks\948.js:1:3078) at c.startActiveSpan (D:\JS project\Bug_report_forum\.next\server\chunks\948.js:1:18133) at a.startActiveSpan (D:\JS project\Bug_report_forum\.next\server\chunks\948.js:1:18667) at D:\JS project\Bug_report_forum\.next\server\chunks\948.js:2:15408 at a.with (D:\JS project\Bug_report_forum\.next\server\chunks\948.js:1:8878) at c.with (D:\JS project\Bug_report_forum\.next\server\chunks\948.js:1:3078) at b.trace (D:\JS project\Bug_report_forum\.next\server\chunks\948.js:2:15362) { description: 'no-store fetch http://localhost:3000/api/Tickets /', digest: 'DYNAMIC_SERVER_USAGE' } TypeError: Cannot destructure property 'tickets' of '(intermediate value)' as it is undefined. at b (D:\JS project\Bug_report_forum\.next\server\app\page.js:1:81719) at processTicksAndRejections (node:internal/process/task_queues:95:5) at runNextTicks (node:internal/process/task_queues:64:3) at listOnTimeout (node:internal/timers:540:9) at process.processTimers (node:internal/timers:514:7) { digest: '3148590653' } Generating static pages (2/6) [== ]TypeError: Cannot destructure property 'tickets' of '(intermediate value)' as it is undefined. at b (D:\JS project\Bug_report_forum\.next\server\app\page.js:1:81719) { digest: '3435398082' } TypeError: Cannot destructure property 'tickets' of '(intermediate value)' as it is undefined. at b (D:\JS project\Bug_report_forum\.next\server\app\page.js:1:81719) { digest: '3435398082' } Error occurred prerendering page "/". Read more: https://nextjs.org/docs/messages/prerender-error TypeError: Cannot destructure property 'tickets' of '(intermediate value)' as it is undefined. at b (D:\JS project\Bug_report_forum\.next\server\app\page.js:1:81719) at processTicksAndRejections (node:internal/process/task_queues:95:5) at runNextTicks (node:internal/process/task_queues:64:3) at listOnTimeout (node:internal/timers:540:9) at process.processTimers (node:internal/timers:514:7) ✓ Generating static pages (6/6) > Export encountered errors on following paths: /page: /
Bonga shadOP
btw this error is happening while exporting
Yes. Instead check the status code before converting to json
And you can try using server actions too
Bonga shadOP
when i use npm run export it will create .next?
@Bonga shad btw this error is happening while exporting
Why are you using that?
@Clown Why are you using that?
Bonga shadOP
for hosting on cpanel
Dont you need to set the output for that in next config?
Btw the error will still occur most likely, so you still need to remove that try catch
NextJS throws around exception when it wants to converse with its server handler(?) immediately
And that try catch gets in the way
I assume rethrowing might work but not sure
Bonga shadOP
showing this error now
@Clown
Bonga shadOP
e
@Anay-208
Let me see
It’ll help you fix the error
@Anay-208 Read this docs first
Bonga shadOP
I did but where do I put this piece of code
this is my dir
@Bonga shad I did but where do I put this piece of code
Where you are generating the Params
@Anay-208 Where you are generating the Params
Bonga shadOP
here?
@Bonga shad this is my dir
In ticket page /[id]/page.jsx
Bonga shadOP
ok
@Anay-208 In ticket page /[id]/page.jsx
Bonga shadOP
it says cant have more than two default functions
@Bonga shad here?
Since you have route.js file, you can’t use static export
@Bonga shad it says cant have more than two default functions
Bonga shadOP
wait nvm
And your using a database
You can’t use static export
Answer
Bonga shadOP
like this, right?
@Bonga shad like this, right?
You can use this, if your route.js returns static data
@Anay-208 You can use this, if your route.js returns static data
Bonga shadOP
i got two route.js which one?
Bonga shadOP
they don't return static data, it fetched from db and then
@Bonga shad they don't return static data, it fetched from db and then
Then you can’t use static build
You can’t do any database related operations in static build
@Anay-208 Then you can’t use static build
Bonga shadOP
so what should i use?
@Bonga shad so what should i use?
You’ll need to just either on Vercel, or cloudflare pages, or any other provider
You won’t be able to use cPanel
You can also host on a vps
@Anay-208 You can also host on a vps
Bonga shadOP
Can you guide me for that?
@Bonga shad Can you guide me for that?
Do you’ve a vps?
@Anay-208 Do you’ve a vps?
Bonga shadOP
Yes
Copy files to the server
Npm run build
Bonga shadOP
do u need some payment for helping?
@Bonga shad do u need some payment for helping?
First of all, we are volunteers, so we don’t need any payment.
@Anay-208 First of all, we are volunteers, so we don’t need any payment.
Bonga shadOP
oh, okay ty so much.
i mean you might get headache helping me bcoz im very new lol
@Anay-208 Copy files to the server
Bonga shadOP
Which dir?
@Bonga shad Which dir?
Any, i usually prefer in ~ dir in the server
And also Make sure, No helper in this server will demand for any payment for helping. However, you can sponsor them
Bonga shadOP
Alright, is regular member helper role?
kind of confuses me lol
@Anay-208 No
Bonga shadOP
Can I skip .next, .git and node modules
@Anay-208 Yes
Bonga shadOP
gotchu, its done
@Bonga shad gotchu, its done
And you can build the app, and use pm2 to start it
Nginx for proxy, and letsencrypt for SSL
And you should be good!
@Anay-208 You can’t do any database related operations in static build
If your issue is resolved, mark this message as a solution
@Anay-208 And you can build the app, and use pm2 to start it
Bonga shadOP
ik about pm2 but how do i build it
@Bonga shad ik about pm2 but how do i build it
Npm run build
@Anay-208 If your issue is resolved, mark this message as a solution
Bonga shadOP
I will, once it gets completely resolved
Run Npm i
First
Bonga shadOP
lol mb i forgot
@Anay-208
You need the generateStaticParams on the page that's fetching /api/Tickets/[id].

Also that seems like a typo in the error message
@Clown You need the generateStaticParams on the page that's fetching `/api/Tickets/[id]`. Also that seems like a typo in the error message
Bonga shadOP
looks like this to me
@Bonga shad <@755810867878297610>
Remove out from next.config
@Bonga shad looks like this to me
Also remove generate static params if you have any
@Anay-208 Remove out from next.config
You added a property out. Remove that from next config js
Bonga shadOP
alr
Original message was deleted
Bonga shadOP
we changed to vps, if u read the chats
@Bonga shad Yes
.:.
Ah yes
Bonga shadOP
@Anay-208 done
@Bonga shad <@755810867878297610> done
Use pm2 now
To start it
@Anay-208 Use pm2 now
Bonga shadOP
what is startup file?
@Bonga shad what is startup file?
I dont know, you just have to use ChatGPT to generate a start command
Just tell it to give command in pm2 which runs npm run start
@Anay-208 I dont know, you just have to use ChatGPT to generate a start command
Bonga shadOP
done here are the logs
@Bonga shad done here are the logs
Now use nginx
To set up a reverse proxy or proxy
@Anay-208 Now use nginx
Bonga shadOP
can u guide me with that?
@Bonga shad can u guide me with that?
You can view some docs online
On how to do that
If you face any issues in that, let me know
Bonga shadOP
i tried earlier but it didn't work
was for something else
I’ll send you a docs link
@Bonga shad resolved?
@Anay-208 <@271974692531732480> resolved?
Bonga shadOP
i'll walkthrough tmrw
@Bonga shad I'm awaiting for any updates
Airedale Terrier
@Anay-208 mind taking a look at this?

https://nextjs-forum.com/post/1251538253912477877
@Bonga shad updates?
@Anay-208 <@271974692531732480> updates?
Bonga shadOP
im out of country
on vacation
@Anay-208 https://phoenixnap.com/kb/nginx-reverse-proxy
So I’ll assume your issue is resolved for now. You can always create a new thread.

Can you mark this message as a solution
@Bonga shad?
@Anay-208 <@271974692531732480>?
Bonga shadOP
im back, will start this tmrw
Bonga shadOP
@Anay-208 here i want to do this with domain
how i do that
@Bonga shad <@755810867878297610> here i want to do this with domain
Add a domain in nginx config
And set Domain A record to that uri
@Anay-208 Add a domain in nginx config
Bonga shadOP
like this?
yes
and you can also add a ssl cert
    # SSL Configuration - Replace the example <domain> with your domain
    ssl_certificate /etc/letsencrypt/live/<domain>/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/<domain>/privkey.pem;
Bonga shadOP
just this?
You can basically view a example here, on how pterodactyl is setting it up
https://pterodactyl.io/panel/1.0/webserver_configuration.html
@Bonga shad resolved?
Hey, can I get updates on this issue?
Bonga shadOP
my vps is having some issues :/
Can you specify?
Hey, can you specify the issues, I'll surely assist you with it!
@Bonga shad Can you specify the issues so I can assist you?
@Anay-208 You can’t use static export
Hey there, if your issue is resolved, mark this message as a solution!
@Anay-208 Hey there, if your issue is resolved, mark this message as a solution!
Bonga shadOP
I’ll mark this solved, will take ur help later for further. Thanks
Rn i am busy with other stuff so sorry
Bonga shadOP
@Anay-208 you stilll there?
Yes
Create another #help-forum if you need more help
And ping me
@Anay-208 Yes
Bonga shadOP
i runned my website but i cannot access