gatsbyjs/gatsby · error · Error
Neither "cache" or "getCache" was passed. getCache must be f
Error message
Neither "cache" or "getCache" was passed. getCache must be function that return Gatsby cache, "cache" must be the Gatsby cache, was ${typeof cache} What it means
Thrown by createFileNodeFromBuffer when neither a `cache` object nor a `getCache` function is supplied. The plugin needs a Gatsby cache instance to persist buffer contents to disk and to deduplicate nodes across builds. After attempting to resolve a cache via `getCache('gatsby-source-filesystem')`, if `cache` is still not an object the call aborts. The template reports the runtime type so callers can see exactly what leaked through.
Source
Thrown at packages/gatsby-source-filesystem/src/create-file-node-from-buffer.js:145
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)
}
if (!name) {
name = hash
}
// Check if we already requested node for this remote file
// and return stored promise if we did.View on GitHub (pinned to 8b06340921)
Solutions
- Pass the Gatsby cache: spread `cache` from the helpers object (actions.createNode still needs createNode; cache comes from the second arg of sourceNodes: ({ cache, actions, createNodeId, createContentDigest })).
- If you do not have direct cache access, pass getCache instead so the plugin resolves its own namespaced cache: getCache(`gatsby-source-filesystem`).
- Verify the value is the actual cache object (typeof cache === 'object' && 'get' in cache) before calling.
- If wrapping the call, forward both cache and getCache from your own helper signature so callers retain control.
Example fix
// before
createFileNodeFromBuffer({
buffer,
createNode,
createNodeId,
})
// after
createFileNodeFromBuffer({
buffer,
cache, // from sourceNodes (helpers.cache)
createNode,
createNodeId,
}) Defensive patterns
Strategy: validation
Validate before calling
function hasCache(opts) {
return (typeof opts.cache === 'object' && opts.cache !== null) ||
typeof opts.getCache === 'function'
}
if (!hasCache({ cache, getCache })) {
throw new Error('Missing Gatsby cache: pass `cache` or `getCache` from helpers')
} Type guard
const isCache = (v) => v !== null && typeof v === 'object' && typeof v.get === 'function' && typeof v.set === 'function'
Try / catch
try { createFileNodeFromBuffer(opts) } catch (e) { if (/Neither "cache" or "getCache"/.test(e.message)) { reporter.panic('Cache not forwarded to createFileNodeFromBuffer; check sourceNodes helpers') } throw e } Prevention
- Always spread cache and getCache from the Gatsby sourceNodes helpers into the call
- Write a tiny wrapper that asserts cache presence with a project-specific error message
- Add an integration test that calls createFileNodeFromBuffer with the full helpers object
When it happens
Trigger: Calling createFileNodeFromBuffer({ buffer, createNode, createNodeId }) without passing cache or getCache; passing cache: undefined or cache: null explicitly; destructuring helpers inside sourceNodes but forgetting to forward cache; passing cache from a custom plugin object instead of the Gatsby-provided cache.
Common situations: Migrating from an older Gatsby version where cache was optional; copying example code that omitted cache; building a custom source plugin on top of gatsby-source-filesystem and only threading through createNode/createNodeId; refactoring that drops the cache key from a destructured helpers spread.
Related errors
- Neither "cache" or "getCache" was passed. getCache must be f
- createNodeId must be a function, was ${typeof createNodeId}
- createNode must be a function, was ${typeof createNode}
- Neither "cache" or "getCache" was passed. getCache must be f
- You must specify either a cache or a directory
AI-assisted analysis of gatsbyjs/gatsby@8b06340921 (2026-08-13).
Data as JSON: /api/errors/1a4b7f2449a4743d.
Report an issue: GitHub.