Next.js Discord

Discord Forum

Debugging slow static page generation

Unanswered
Norwegian Lundehund posted this in #help-forum
Open in Discord
Avatar
Norwegian LundehundOP
Hi there, we're noticing that in CI, our next.js builds are timing out and restarting during the "Generating static pages" stage - we're using the pages directory and babel (no swc yet) in our project:
warn  - Restarted static page generation for /setup because it took more than 60 seconds


I'm wondering if anyone has some ideas on how to debug this issue. I'm particularly interested in ways I can visualize the trace file that's generated with next build --profile - can't seem to figure it out.
Any help is appreciated! 🙏

17 Replies

Avatar
you can also just add a bunch of console.log to the getStaticProps of your CI to see where it is stuck
Avatar
Norwegian LundehundOP
not sure I follow how that would help? most of our static pages don't have getStaticProps fwiw.
Avatar
American black bear
The same problem occurred yesterday on vercel
Avatar
how is /setup taking that long then? can you show me the code that is run when /setup is statically generated?
Avatar
Norwegian LundehundOP
My current hunch is that there is like an optimizely provider that wraps the react tree and tries to do a network call during SSG and then it times out.
I cannot share a meaningful snippet because there's a ton of context providers and wrapper components in _app.tsx and you won't get the full picture without all that (sadly cannot share the whole thing).
Avatar
_app.tsx doesn't have static data fetching methods so it doesn't take long to generate
the issue lies in the static data fetching methods (getStatic(Paths|Props)) in your pages
Avatar
Norwegian LundehundOP
None of the static pages I have export getStatic(Paths|Props) functions
Avatar
then honestly i can't think of what could take static generation 60 seconds
does it happen now? when you retry building
does it happen when you build locally?
Avatar
Norwegian LundehundOP
No worries 🙂
and yes on all counts.
I'd just like to read the .next/trace that gets generated with --profile flag
so far I cannot open it with the zipkin ui or react-devtools
Avatar
American black bear
I don't know if it will help you. All night yesterday there was an error similar to yours on vercel. Now, with a new build, it has disappeared.
Avatar
Norwegian LundehundOP
That's useful to know. I'm not using Vercel for our project (would love to though).