Fix 'Build Exceeded Maximum Allowed Runtime' on Netlify

$ Build exceeded maximum allowed runtime

Also appears as:

  • Build timed out
  • Build exceeded the 30 minute timeout
  • Exceeded build time limit
  • Build cancelled due to timeout

Symptoms

  • Build runs for a long time and then fails
  • Build log shows progress but is killed before completion
  • Large sites that previously built fine start timing out
  • Timeout occurs during static page generation or image processing

What Causes This Error

Too many pages being statically generated

Common

Frameworks like Next.js, Gatsby, and Astro generate all static pages during the build. If you have thousands of pages, the generation process can exceed Netlify's 30-minute build limit.

Heavy image processing

Common

Image optimization during builds (resizing, format conversion, generating responsive sizes) is CPU-intensive. Sites with hundreds of images can hit the timeout during this step.

Slow external API calls during build

Occasional

If your build fetches data from external APIs (CMS, databases, third-party services), slow or rate-limited responses can significantly extend build time.

Inefficient build configuration

Occasional

Missing build cache, unnecessary rebuilds, or redundant processing steps can all contribute to longer build times.

How to Fix It

Fix 1: Use incremental or on-demand generation

  1. Instead of generating all pages at build time, use ISR (Next.js), hybrid mode (Astro), or deferred static generation
  2. Generate only the most important pages at build time
  3. Let other pages be generated on the first request
Next.js: app/posts/[slug]/page.tsx
// Generate only the top 100 posts at build time
export async function generateStaticParams() {
  const posts = await getTopPosts(100)
  return posts.map(post => ({ slug: post.slug }))
}

// Other posts will be generated on demand
export const dynamicParams = true

Verify: Rebuild and verify the build completes within the time limit.

Fix 2: Optimize image processing

  1. Pre-process images before they enter the build pipeline
  2. Use a CDN or image service (Cloudinary, Imgix) instead of build-time processing
  3. Reduce the number of generated image variants
  4. Compress source images to smaller dimensions
next.config.js
module.exports = {
  images: {
    // Use external image optimization
    loader: 'custom',
    loaderFile: './image-loader.js',
    // Or disable optimization entirely for testing
    // unoptimized: true,
  },
}

Verify: Check build logs to confirm image processing time is reduced.

Fix 3: Enable and optimize build caching

  1. Ensure Netlify's build cache is not disabled
  2. Use framework-specific cache plugins (gatsby-plugin-netlify, etc.)
  3. Cache external API responses locally during the build
  4. Avoid clearing the cache unnecessarily

Verify: Compare build times between cached and uncached builds.

Fix 4: Parallelize and batch API calls

  1. Use Promise.all() for concurrent API requests during builds
  2. Implement request batching for CMS queries
  3. Add local caching for API responses to avoid redundant calls
  4. Set reasonable timeouts on external API calls
Parallel data fetching
// Instead of sequential:
const posts = await fetchPosts()
const authors = await fetchAuthors()

// Use parallel:
const [posts, authors] = await Promise.all([
  fetchPosts(),
  fetchAuthors(),
])

Verify: Check build logs for reduced total API fetch time.

How to Prevent This

1.

Profile your build time regularly — add timing logs to your build scripts to identify slow steps.

2.

Use the Netli.fyi app to track build durations over time and catch regressions.

3.

Implement incremental/on-demand generation from the start rather than waiting for timeouts.

4.

Pre-process images before commit rather than during the build.

5.

Consider splitting your site into multiple Netlify sites if it grows beyond what a single build can handle.

Perttu Lähteenlahti

Perttu Lähteenlahti

Developer Advocate at RevenueCat and creator of Netli.fyi. Building on Netlify since 2019. Writes from hands-on experience deploying dozens of production sites.

Manage Netlify on the go

Download Netli.fyi and monitor your sites, check deploys, and manage your projects from anywhere.