gatsbyjs/gatsby · error
Failed to locate or install LMDB binary for functions execut
Error message
Failed to locate or install LMDB binary for functions execution platform/arch (${functionsTarget.platform}/${functionsTarget.arch}) What it means
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.
Source
Thrown at packages/gatsby/src/schema/graphql-engine/bundle-webpack.ts:387
// we need to make sure we have internal packages cache directory setup for current lambda target
// before we attempt to check if we can reuse those packages
await createInternalPackagesCacheDir(functionsTarget)
const [lmdbPackageInfo, sharpPackageInfo] = await installMissing(
[
checkIfNeedToInstallMissingLmdb(functionsTarget),
checkIfNeedToInstallMissingSharp(functionsTarget, currentTarget),
],
functionsTarget
)
if (!lmdbPackageInfo) {
throw new Error(`Failed to find required LMDB binary`)
} else if (functionsTarget.platform === `linux`) {
// function execution platform is primarily linux, which is tested the most, so we only force that specific binary
// to not cause untested code paths
if (lmdbPackageInfo.needToInstall) {
throw new Error(
`Failed to locate or install LMDB binary for functions execution platform/arch (${functionsTarget.platform}/${functionsTarget.arch})`
)
}
forcedLmdbBinaryModule = `${lmdbPackageInfo.packageLocation}/node.abi83.glibc.node`
}
if (sharpPackageInfo) {
if (sharpPackageInfo.needToInstall) {
throw new Error(
`Failed to locate or install Sharp binary for functions execution platform/arch (${functionsTarget.platform}/${functionsTarget.arch})`
)
}
dynamicAliases[`sharp$`] = sharpPackageInfo.packageLocation
}
const compiler = webpack({
name: `Query Engine`,View on GitHub (pinned to 8b06340921)
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.
Example fix
# before - building linux functions on macOS with missing linux lmdb prebuild # after - build inside the target linux env docker run --rm -v "$PWD":/srv -w /srv node:18 bash -lc "npm ci && gatsby build --functions-platform=linux --functions-arch=x64"
Defensive patterns
Strategy: validation
Validate before calling
// When cross-targeting linux, build inside a matching linux container.
// Pre-check the linux lmdb prebuild file exists on disk.
const fs = require('fs'), path = require('path')
function linuxLmdbBinaryPresent() {
try {
const lmdbDir = path.dirname(require.resolve('lmdb'))
return fs.readdirSync(lmdbDir).some(f => /node\.abi\d+\.glibc\.node$/.test(f))
} catch { return false }
} Type guard
function isLinuxTarget(t) { return t?.platform === 'linux' } Prevention
- 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.
When it happens
Trigger: 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).
Common situations: 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.
Related errors
- Target platform/arch for functions execution (${functionsTar
- Failed to find required LMDB binary
- Failed to locate or install Sharp binary for functions execu
- Incompatible DSG/SSR executing environment. Function was bui
- Bad value at ${path}: ${inspect(fieldValue)}
AI-assisted analysis of gatsbyjs/gatsby@8b06340921 (2026-08-13).
Data as JSON: /api/errors/799e8abc047460c1.
Report an issue: GitHub.