{"record":{"id":"1a4b7f2449a4743d","repo":"gatsbyjs/gatsby","slug":"neither-cache-or-getcache-was-passed-getcache","errorCode":null,"errorMessage":"Neither \"cache\" or \"getCache\" was passed. getCache must be function that return Gatsby cache, \"cache\" must be the Gatsby cache, was ${typeof cache}","messagePattern":"Neither \"cache\" or \"getCache\" was passed\\. getCache must be function that return Gatsby cache, \"cache\" must be the Gatsby cache, was (.+?)","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/gatsby-source-filesystem/src/create-file-node-from-buffer.js","lineNumber":145,"sourceCode":"  name,\n}) => {\n  // validation of the input\n  // without this it's notoriously easy to pass in the wrong `createNodeId`\n  // see gatsbyjs/gatsby#6643\n  if (typeof createNodeId !== `function`) {\n    throw new Error(\n      `createNodeId must be a function, was ${typeof createNodeId}`\n    )\n  }\n  if (typeof createNode !== `function`) {\n    throw new Error(`createNode must be a function, was ${typeof createNode}`)\n  }\n  if (typeof getCache === `function`) {\n    // use cache of this plugin and not cache of function caller\n    cache = getCache(`gatsby-source-filesystem`)\n  }\n  if (typeof cache !== `object`) {\n    throw new Error(\n      `Neither \"cache\" or \"getCache\" was passed. getCache must be function that return Gatsby cache, \"cache\" must be the Gatsby cache, was ${typeof cache}`\n    )\n  }\n\n  if (!buffer) {\n    return Promise.reject(`bad buffer: ${buffer}`)\n  }\n\n  if (!hash) {\n    hash = createContentDigest(buffer)\n  }\n\n  if (!name) {\n    name = hash\n  }\n\n  // Check if we already requested node for this remote file\n  // and return stored promise if we did.","sourceCodeStart":127,"sourceCodeEnd":163,"githubUrl":"https://github.com/gatsbyjs/gatsby/blob/8b06340921ffdf23125a365b9c9923690cb62ce6/packages/gatsby-source-filesystem/src/create-file-node-from-buffer.js#L127-L163","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\ncreateFileNodeFromBuffer({\n  buffer,\n  createNode,\n  createNodeId,\n})\n\n// after\ncreateFileNodeFromBuffer({\n  buffer,\n  cache,        // from sourceNodes (helpers.cache)\n  createNode,\n  createNodeId,\n})","handlingStrategy":"validation","validationCode":"function hasCache(opts) {\n  return (typeof opts.cache === 'object' && opts.cache !== null) ||\n         typeof opts.getCache === 'function'\n}\nif (!hasCache({ cache, getCache })) {\n  throw new Error('Missing Gatsby cache: pass `cache` or `getCache` from helpers')\n}","typeGuard":"const isCache = (v) => v !== null && typeof v === 'object' && typeof v.get === 'function' && typeof v.set === 'function'","tryCatchPattern":"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 }","preventionTips":["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"],"tags":["gatsby","validation","config","cache"],"backgroundTag":null,"analyzedSha":"8b06340921ffdf23125a365b9c9923690cb62ce6","analyzedAt":"2026-08-13T02:36:21.405Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}