{"record":{"id":"99affa0fc125cfba","repo":"gatsbyjs/gatsby","slug":"an-error-occurred-finding-a-node-by-it-s-type-thi","errorCode":null,"errorMessage":"An error occurred finding a node by it's type. This is likely a bug in gatsby. If you experience this error please open an issue.","messagePattern":"An error occurred finding a node by it's type\\. This is likely a bug in gatsby\\. If you experience this error please open an issue\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/gatsby/src/redux/reducers/nodes-by-type.ts","lineNumber":14,"sourceCode":"import { IGatsbyNode, IGatsbyState, ActionsUnion } from \"../types\"\n\nconst getNodesOfType = (\n  node: IGatsbyNode,\n  state: IGatsbyState[\"nodesByType\"]\n): Map<string, IGatsbyNode> => {\n  const { type } = node.internal\n  if (!state.has(type)) {\n    state.set(type, new Map())\n  }\n  const nodeByType = state.get(type)\n\n  if (!nodeByType) {\n    throw new Error(\n      `An error occurred finding a node by it's type. This is likely a bug in gatsby. If you experience this error please open an issue.`\n    )\n  }\n\n  return nodeByType\n}\n\nexport const nodesByTypeReducer = (\n  state: IGatsbyState[\"nodesByType\"] = new Map(),\n  action: ActionsUnion\n): IGatsbyState[\"nodesByType\"] => {\n  switch (action.type) {\n    case `DELETE_CACHE`:\n      return new Map()\n\n    case `CREATE_NODE`: {\n      const node = action.payload\n      const nodesOfType = getNodesOfType(node, state)","sourceCodeStart":1,"sourceCodeEnd":32,"githubUrl":"https://github.com/gatsbyjs/gatsby/blob/8b06340921ffdf23125a365b9c9923690cb62ce6/packages/gatsby/src/redux/reducers/nodes-by-type.ts#L1-L32","documentation":"getNodesOfType is a helper inside the nodesByType reducer that lazily creates a Map for a node type and then reads it back. It throws if state.get(type) returns undefined immediately after state.set(type, new Map()), which is logically impossible for a normal Map and therefore treated as a Gatsby internal bug. The throw is a defensive non-null guard for TypeScript over a Map operation that should always succeed.","triggerScenarios":"Dispatching any node action (CREATE_NODE, DELETE_NODE, etc.) whose node.internal.type triggers getNodesOfType, in the pathological case where Map.prototype.get returns undefined right after Map.prototype.set. Not reproducible through normal API usage.","commonSituations":"Effectively unreachable; would only surface from memory corruption, a custom Map-like state object violating Map semantics, or a severe runtime/JS engine bug. If reported, it is treated as a Gatsby defect.","solutions":["Report to Gatsby as an internal bug with the node type and full stack trace.","Clear .cache and node_modules and reinstall/rebuild to rule out a corrupted build environment.","Update Gatsby to the latest version."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"// Defensive: this is an internal invariant; surface and reset.\ntry {\n  // ... node operations ...\n} catch (e) {\n  if (/likely a bug in gatsby/.test(e.message)) {\n    report.error(e)\n  } else throw e\n}","preventionTips":["Do not replace redux state Maps with custom non-conforming objects.","Run gatsby clean if node-by-type state appears corrupted.","Report reproducible occurrences upstream."],"tags":["nodes-by-type","reducer","internal-bug","state"],"backgroundTag":null,"analyzedSha":"8b06340921ffdf23125a365b9c9923690cb62ce6","analyzedAt":"2026-08-13T02:36:21.405Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}