{"record":{"id":"d3d9443b1c97d271","repo":"gatsbyjs/gatsby","slug":"failed-to-write-out-requires","errorCode":null,"errorMessage":"Failed to write out requires","messagePattern":"Failed to write out requires","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"packages/gatsby/src/services/write-out-requires.ts","lineNumber":20,"sourceCode":"import { writeAll } from \"../bootstrap/requires-writer\"\nimport { IQueryRunningContext } from \"../state-machines/query-running/types\"\nimport { assertStore } from \"../utils/assert-store\"\n\nexport async function writeOutRequires({\n  store,\n  parentSpan,\n}: Partial<IQueryRunningContext>): Promise<void> {\n  assertStore(store)\n\n  // Write out files.\n  const activity = reporter.activityTimer(`write out requires`, {\n    parentSpan,\n  })\n  activity.start()\n  try {\n    await writeAll(store.getState())\n  } catch (err) {\n    reporter.panic(`Failed to write out requires`, err)\n  }\n  activity.end()\n}\n","sourceCodeStart":2,"sourceCodeEnd":24,"githubUrl":"https://github.com/gatsbyjs/gatsby/blob/8b06340921ffdf23125a365b9c9923690cb62ce6/packages/gatsby/src/services/write-out-requires.ts#L2-L24","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Run `gatsby clean` then re-run the build.","Inspect the attached `err` -- if it is a filesystem error (ENOENT, EACCES), resolve the permission/path/disk issue.","If the error references a specific component path, verify that file exists and the plugin/page referencing it is correct.","Check available disk space."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Verify store state integrity before write-out-requires\nfunction validateStoreForWriteOut(store) {\n  const state = store.getState()\n  if (!state.components || !state.staticQueryComponents) {\n    throw new Error('Store state missing components or staticQueryComponents')\n  }\n}","typeGuard":null,"tryCatchPattern":"// The internal code already wraps writeAll in try/catch and panics.\n// At the caller level, ensure disk space and permissions.\ntry {\n  await writeOutRequires({ store, parentSpan })\n} catch (err) {\n  console.error('Write-out-requires failed:', err)\n  // Clean and retry\n  await cleanCache()\n}","preventionTips":["Ensure sufficient disk space and write permissions in the project directory.","Run gatsby clean between builds on suspicion of cache corruption.","On Windows, exclude .cache from antivirus scanning."],"tags":["filesystem","cache","requires-writer","build","redux"],"backgroundTag":null,"analyzedSha":"8b06340921ffdf23125a365b9c9923690cb62ce6","analyzedAt":"2026-08-13T02:36:21.405Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}