{"record":{"id":"ef3f66d2cb04adff","repo":"gatsbyjs/gatsby","slug":"failed-to-find-required-lmdb-binary","errorCode":null,"errorMessage":"Failed to find required LMDB binary","messagePattern":"Failed to find required LMDB binary","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/gatsby/src/schema/graphql-engine/bundle-webpack.ts","lineNumber":382,"sourceCode":"  const functionsTarget = getFunctionsTargetPlatformAndTarget()\n\n  const dynamicAliases: Record<string, string> = {}\n  let forcedLmdbBinaryModule: string | undefined = undefined\n\n  // we need to make sure we have internal packages cache directory setup for current lambda target\n  // before we attempt to check if we can reuse those packages\n  await createInternalPackagesCacheDir(functionsTarget)\n\n  const [lmdbPackageInfo, sharpPackageInfo] = await installMissing(\n    [\n      checkIfNeedToInstallMissingLmdb(functionsTarget),\n      checkIfNeedToInstallMissingSharp(functionsTarget, currentTarget),\n    ],\n    functionsTarget\n  )\n\n  if (!lmdbPackageInfo) {\n    throw new Error(`Failed to find required LMDB binary`)\n  } else if (functionsTarget.platform === `linux`) {\n    // function execution platform is primarily linux, which is tested the most, so we only force that specific binary\n    // to not cause untested code paths\n    if (lmdbPackageInfo.needToInstall) {\n      throw new Error(\n        `Failed to locate or install LMDB binary for functions execution platform/arch (${functionsTarget.platform}/${functionsTarget.arch})`\n      )\n    }\n\n    forcedLmdbBinaryModule = `${lmdbPackageInfo.packageLocation}/node.abi83.glibc.node`\n  }\n\n  if (sharpPackageInfo) {\n    if (sharpPackageInfo.needToInstall) {\n      throw new Error(\n        `Failed to locate or install Sharp binary for functions execution platform/arch (${functionsTarget.platform}/${functionsTarget.arch})`\n      )\n    }","sourceCodeStart":364,"sourceCodeEnd":400,"githubUrl":"https://github.com/gatsbyjs/gatsby/blob/8b06340921ffdf23125a365b9c9923690cb62ce6/packages/gatsby/src/schema/graphql-engine/bundle-webpack.ts#L364-L400","documentation":"After running installMissing for both lmdb and sharp, bundle-webpack checks that it got a truthy lmdbPackageInfo. A falsy result means checkIfNeedToInstallMissingLmdb returned undefined (e.g. it early-returned undefined because lmdb's package.json could not be read, or no optional dependency matched and it returned undefined instead of throwing). Gatsby treats a missing LMDB binary as fatal because the query engine persists state in lmdb.","triggerScenarios":"installMissing returns [undefined, sharpInfo] for lmdb - i.e. checkIfNeedToInstallMissingLmdb returned undefined rather than a usable info object. Happens when lmdb's package.json cannot be resolved/read (caught and returns undefined) or the binary resolution path silently fails.","commonSituations":"Broken/incomplete node_modules (lmdb not properly installed or its package.json missing after a partial install); corrupted .cache; CI caching that stripped native package files; an npm/pnpm hoisting layout where require.resolve('lmdb') points somewhere unexpected.","solutions":["Reinstall dependencies cleanly: rm -rf node_modules package-lock.json && npm install.","Clear Gatsby cache: gatsby clean (removes .cache and public).","Verify lmdb is installed and resolvable: node -e \"console.log(require.resolve('lmdb'))\".","If using a monorepo/hoisting, ensure lmdb is resolvable from the gatsby package's context (add an override/resolution if needed)."],"exampleFix":"# before - corrupted install triggers the throw\n# after\ngatsby clean\nrm -rf node_modules package-lock.json\nnpm install\ngatsby build","handlingStrategy":"validation","validationCode":"// Pre-flight: ensure lmdb resolves and its package.json is readable.\nfunction preflightLmdb() {\n  try {\n    const path = require.resolve('lmdb')\n    require('fs').readFileSync(require('path').join(require('path').dirname(path), 'package.json'), 'utf8')\n    return true\n  } catch {\n    return false\n  }\n}\nif (!preflightLmdb()) throw new Error('lmdb not properly installed; run npm ci')","typeGuard":"function lmdbInstalled() {\n  try { require.resolve('lmdb'); return true } catch { return false }\n}","tryCatchPattern":null,"preventionTips":["Do not prune optionalDependencies in CI caches.","Run npm ci from a clean lockfile in the build environment.","Verify require.resolve('lmdb') works before building."],"tags":["bundle-webpack","lmdb","functions","native-binary","install"],"backgroundTag":null,"analyzedSha":"8b06340921ffdf23125a365b9c9923690cb62ce6","analyzedAt":"2026-08-13T02:36:21.405Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}