gatsbyjs/gatsby · critical

Failed to write out requires

Error message

Failed to write out requires

What it means

The writeOutRequires step writes the generated requires file (which maps component/templates to their module paths for the SSR/query runtime) based on Redux store state. If writeAll throws -- typically a filesystem error or invalid state -- the panic wraps the underlying error.

Source

Thrown at packages/gatsby/src/services/write-out-requires.ts:20

import { writeAll } from "../bootstrap/requires-writer"
import { IQueryRunningContext } from "../state-machines/query-running/types"
import { assertStore } from "../utils/assert-store"

export async function writeOutRequires({
  store,
  parentSpan,
}: Partial<IQueryRunningContext>): Promise<void> {
  assertStore(store)

  // Write out files.
  const activity = reporter.activityTimer(`write out requires`, {
    parentSpan,
  })
  activity.start()
  try {
    await writeAll(store.getState())
  } catch (err) {
    reporter.panic(`Failed to write out requires`, err)
  }
  activity.end()
}

View on GitHub (pinned to 8b06340921)

Solutions

  1. Run `gatsby clean` then re-run the build.
  2. Inspect the attached `err` -- if it is a filesystem error (ENOENT, EACCES), resolve the permission/path/disk issue.
  3. If the error references a specific component path, verify that file exists and the plugin/page referencing it is correct.
  4. Check available disk space.
Defensive patterns

Strategy: try-catch

Validate before calling

// Verify store state integrity before write-out-requires
function validateStoreForWriteOut(store) {
  const state = store.getState()
  if (!state.components || !state.staticQueryComponents) {
    throw new Error('Store state missing components or staticQueryComponents')
  }
}

Try / catch

// The internal code already wraps writeAll in try/catch and panics.
// At the caller level, ensure disk space and permissions.
try {
  await writeOutRequires({ store, parentSpan })
} catch (err) {
  console.error('Write-out-requires failed:', err)
  // Clean and retry
  await cleanCache()
}

Prevention

When it happens

Trigger: writeAll(store.getState()) throws, which can happen on filesystem write errors, invalid/missing component paths in state, or a corrupted store state where components or static queries reference non-existent modules.

Common situations: Disk write permission or space issues in .cache. A plugin registered a component with a path that doesn't exist on disk. Corrupted Redux state after a crash. Antivirus locking files on Windows.

Related errors


AI-assisted analysis of gatsbyjs/gatsby@8b06340921 (2026-08-13). Data as JSON: /api/errors/d3d9443b1c97d271. Report an issue: GitHub.