gatsbyjs/gatsby · error · Error

An error occurred finding a node by it's type. This is likel

Error message

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.

What it means

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.

Source

Thrown at packages/gatsby/src/redux/reducers/nodes-by-type.ts:14

import { IGatsbyNode, IGatsbyState, ActionsUnion } from "../types"

const getNodesOfType = (
  node: IGatsbyNode,
  state: IGatsbyState["nodesByType"]
): Map<string, IGatsbyNode> => {
  const { type } = node.internal
  if (!state.has(type)) {
    state.set(type, new Map())
  }
  const nodeByType = state.get(type)

  if (!nodeByType) {
    throw new Error(
      `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.`
    )
  }

  return nodeByType
}

export const nodesByTypeReducer = (
  state: IGatsbyState["nodesByType"] = new Map(),
  action: ActionsUnion
): IGatsbyState["nodesByType"] => {
  switch (action.type) {
    case `DELETE_CACHE`:
      return new Map()

    case `CREATE_NODE`: {
      const node = action.payload
      const nodesOfType = getNodesOfType(node, state)

View on GitHub (pinned to 8b06340921)

Solutions

  1. Report to Gatsby as an internal bug with the node type and full stack trace.
  2. Clear .cache and node_modules and reinstall/rebuild to rule out a corrupted build environment.
  3. Update Gatsby to the latest version.
Defensive patterns

Strategy: try-catch

Try / catch

// Defensive: this is an internal invariant; surface and reset.
try {
  // ... node operations ...
} catch (e) {
  if (/likely a bug in gatsby/.test(e.message)) {
    report.error(e)
  } else throw e
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


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