{"record":{"id":"799e8abc047460c1","repo":"gatsbyjs/gatsby","slug":"failed-to-locate-or-install-lmdb-binary-for-functi","errorCode":null,"errorMessage":"Failed to locate or install LMDB binary for functions execution platform/arch (${functionsTarget.platform}/${functionsTarget.arch})","messagePattern":"Failed to locate or install LMDB binary for functions execution platform/arch \\((.+?)/(.+?)\\)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/gatsby/src/schema/graphql-engine/bundle-webpack.ts","lineNumber":387,"sourceCode":"  // 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    }\n    dynamicAliases[`sharp$`] = sharpPackageInfo.packageLocation\n  }\n\n  const compiler = webpack({\n    name: `Query Engine`,","sourceCodeStart":369,"sourceCodeEnd":405,"githubUrl":"https://github.com/gatsbyjs/gatsby/blob/8b06340921ffdf23125a365b9c9923690cb62ce6/packages/gatsby/src/schema/graphql-engine/bundle-webpack.ts#L369-L405","documentation":"Even when an lmdb prebuilt package exists for the target, on linux Gatsby requires the binary to already be present (not require installation) and forces a specific ABI/node filename. If lmdbPackageInfo.needToInstall is true on linux - meaning the binary could not be located and would need installation - it throws, because the bundler cannot install native binaries into the bundle at this stage. This is a stricter check than the non-linux path.","triggerScenarios":"functionsTarget.platform === 'linux' AND installMissing returned an lmdbPackageInfo whose needToInstall is true (binary was not found in the expected prebuilt package location, so the resolver fell back to 'needs install'). Distinct from error 155 (no prebuild listed at all) and 156 (no info returned).","commonSituations":"Building linux functions on a non-linux host where the linux lmdb prebuild package is listed but its .node file is missing from node_modules (CI cache truncation, partial install, pnpm hoisting); ABI mismatch between expected node.abi83.glibc.node and what shipped; wrong lmdb version pulled by an override.","solutions":["Install the linux lmdb prebuild explicitly: npm install in an environment matching the target (e.g. a linux Docker container) so the optional dependency is laid out on disk.","Disable CI cache truncation of optionalDependencies for native packages, or use a cache that preserves them.","Run gatsby clean and reinstall to re-fetch the prebuilt binary.","Pin/override lmdb to a version whose linux prebuild ABI matches the runtime node."],"exampleFix":"# before - building linux functions on macOS with missing linux lmdb prebuild\n# after - build inside the target linux env\ndocker run --rm -v \"$PWD\":/srv -w /srv node:18 bash -lc \"npm ci && gatsby build --functions-platform=linux --functions-arch=x64\"","handlingStrategy":"validation","validationCode":"// When cross-targeting linux, build inside a matching linux container.\n// Pre-check the linux lmdb prebuild file exists on disk.\nconst fs = require('fs'), path = require('path')\nfunction linuxLmdbBinaryPresent() {\n  try {\n    const lmdbDir = path.dirname(require.resolve('lmdb'))\n    return fs.readdirSync(lmdbDir).some(f => /node\\.abi\\d+\\.glibc\\.node$/.test(f))\n  } catch { return false }\n}","typeGuard":"function isLinuxTarget(t) { return t?.platform === 'linux' }","tryCatchPattern":null,"preventionTips":["Build linux functions inside a linux container so prebuilds are fetched.","Keep optionalDependencies in package-lock and CI cache.","Pin node/lmdb ABI versions consistently across build and runtime."],"tags":["bundle-webpack","lmdb","functions","linux","native-binary"],"backgroundTag":null,"analyzedSha":"8b06340921ffdf23125a365b9c9923690cb62ce6","analyzedAt":"2026-08-13T02:36:21.405Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}