gatsbyjs/gatsby · error · Error

createNode must be a function, was ${typeof createNode}

Error message

createNode must be a function, was ${typeof createNode}

What it means

Thrown by createFileNodeFromBuffer when the createNode parameter is not a function. Like the createNodeId check, this validates that the Gatsby createNode action (used to add nodes to the data layer) is correctly passed as a callable function.

Source

Thrown at packages/gatsby-source-filesystem/src/create-file-node-from-buffer.js:138

  hash,
  cache,
  createNode,
  getCache,
  parentNodeId = null,
  createNodeId,
  ext,
  name,
}) => {
  // validation of the input
  // without this it's notoriously easy to pass in the wrong `createNodeId`
  // see gatsbyjs/gatsby#6643
  if (typeof createNodeId !== `function`) {
    throw new Error(
      `createNodeId must be a function, was ${typeof createNodeId}`
    )
  }
  if (typeof createNode !== `function`) {
    throw new Error(`createNode must be a function, was ${typeof createNode}`)
  }
  if (typeof getCache === `function`) {
    // use cache of this plugin and not cache of function caller
    cache = getCache(`gatsby-source-filesystem`)
  }
  if (typeof cache !== `object`) {
    throw new Error(
      `Neither "cache" or "getCache" was passed. getCache must be function that return Gatsby cache, "cache" must be the Gatsby cache, was ${typeof cache}`
    )
  }

  if (!buffer) {
    return Promise.reject(`bad buffer: ${buffer}`)
  }

  if (!hash) {
    hash = createContentDigest(buffer)
  }

View on GitHub (pinned to 8b06340921)

Solutions

  1. Pass the createNode action function from Gatsby's actions object.
  2. Ensure you pass the function reference, not the result of calling it.
  3. Verify the variable name in your destructuring matches the expected parameter.
  4. Check that actions is the Gatsby actions object, not a custom object.

Example fix

// before
await createFileNodeFromBuffer({ buffer, name: 'file', createNode: {} })
// after
await createFileNodeFromBuffer({ buffer, name: 'file', createNode })
// where createNode is from: const { createNode } = actions
Defensive patterns

Strategy: type-guard

Validate before calling

// Ensure createNode is a function before calling
if (typeof createNode !== 'function') {
  throw new TypeError(`createNode must be a function, got ${typeof createNode}`)
}

Type guard

const isCreateNode = (val: unknown): val is (node: unknown) => void =>
  typeof val === 'function'

Prevention

When it happens

Trigger: typeof createNode !== 'function' because the caller passed the wrong value — e.g., a node object instead of the action function, or forgot to pass it entirely (undefined).

Common situations: A plugin calls createFileNodeFromBuffer without destructuring createNode from actions, passes createNode(payload) result instead of createNode itself, or names the variable differently.

Related errors


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