Marked as helpful by the asker
Raising the heap only moves the wall. Two better levers:
- Don't prebuild everything. Return only recent/popular posts from
generateStaticParams, the rest render on first request and get cached:
export const dynamicParams = true; // default, but be explicit
export async function generateStaticParams() {
const posts = await getPosts();
return posts.slice(0, 50).map((p) => ({ slug: p.slug }));
}- Check what each page loads. If every post page imports a helper that reads all 300 MDX files (for "related posts" or the sidebar), you parse 300 × 300 files. Build the index once into a small JSON and read that.
In your case I'd bet on #2, memory growing linearly with post count usually means that.
It was #2. The sidebar component called getAllPosts() which compiled every MDX file including the body. Made a lightweight getPostMeta() that only reads frontmatter. Build is 2 minutes and I removed the NODE_OPTIONS again. valentina_s · edited
Same bug in my blog, getAllPosts() in the sidebar. Thanks for posting the follow-up. sam_builds · edited