{"record":{"id":"c2d17313013f55b0","repo":"oven-sh/bun","slug":"failed-to-install-package-module","errorCode":null,"errorMessage":"Failed to install package \"${module}\"","messagePattern":"Failed to install package \"(.+?)\"","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/bun-release/src/npm/install.ts","lineNumber":25,"sourceCode":"import { abi, arch, os, supportedPlatforms } from \"../platform\";\nimport { spawn } from \"../spawn\";\n\ndeclare const version: string;\ndeclare const module: string;\ndeclare const owner: string;\n\nexport async function importBun(): Promise<string> {\n  if (!supportedPlatforms.length) {\n    throw new Error(`Unsupported platform: ${os} ${arch} ${abi || \"\"}`);\n  }\n  for (const platform of supportedPlatforms) {\n    try {\n      return await requireBun(platform);\n    } catch (error) {\n      debug(\"requireBun failed\", error);\n    }\n  }\n  throw new Error(`Failed to install package \"${module}\"`);\n}\n\nasync function requireBun(platform: Platform): Promise<string> {\n  const module = `${owner}/${platform.bin}`;\n  function resolveBun() {\n    const exe = require.resolve(join(module, platform.exe));\n    const { exitCode, stderr, stdout } = spawn(exe, [\"--version\"]);\n    if (exitCode === 0) {\n      return exe;\n    }\n    throw new Error(stderr || stdout);\n  }\n  try {\n    return resolveBun();\n  } catch (cause) {\n    debug(\"resolveBun failed\", cause);\n    error(\n      `Failed to find package \"${module}\".`,","sourceCodeStart":7,"sourceCodeEnd":43,"githubUrl":"https://github.com/oven-sh/bun/blob/8c5296ac459e8252d3cd702f3fbcbb0c249d95d5/packages/bun-release/src/npm/install.ts#L7-L43","documentation":"importBun() iterates every supported platform package; each requireBun() resolves the downloaded binary and sanity-checks it by spawning '<exe> --version'. If every attempt throws (resolve failure, non-zero exit, spawn error) the installer gives up with this final error naming the release module it tried to install. The per-attempt causes are only visible via the debug log.","triggerScenarios":"The downloaded bun binary fails to execute (exec format error under wrong emulation, glibc too old, missing interp), extraction or resolution failed, or the download step never completed because registry.npmjs.org was unreachable through a proxy/firewall.","commonSituations":"Corporate proxies or registry mirrors (Artifactory/Nexus) blocking or mangling tarballs; old glibc distros (CentOS 7) where bun will not start; qemu-user containers; transient npm registry outages during postinstall.","solutions":["Check network reachability of registry.npmjs.org and proxy env vars (HTTPS_PROXY/HTTP_PROXY), then retry the install","Run the downloaded binary manually to see the real spawn error: node_modules/<platform-pkg>/bin/bun --version","If glibc is too old, use the Docker image or a musl-hosting equivalent","Fall back to the standalone install script, which does not depend on the npm postinstall path"],"exampleFix":"# before\nnpm i -g bun   # -> Failed to install package \"bun\"\n\n# after\nnpm cache clean --force && npm i -g bun   # retry after clearing cache\n./node_modules/bun-linux-x64/bin/bun --version   # surface the real spawn error\ncurl -fsSL https://bun.sh/install | bash   # fallback installer","handlingStrategy":"retry","validationCode":"// pre-flight: can we reach the registry and execute downloaded binaries?\nconst res = await fetch('https://registry.npmjs.org/-/ping');\nif (!res.ok) throw new Error(`registry unreachable (${res.status}) — fix proxy before install`);","typeGuard":null,"tryCatchPattern":"let lastError: unknown;\nfor (let attempt = 0; attempt < 3; attempt++) {\n  try {\n    exePath = await importBun();\n    break;\n  } catch (err) {\n    lastError = err;\n  }\n}\nif (!exePath) throw lastError;","preventionTips":["Verify registry/proxy env before scripted installs in CI","Test-exec the downloaded binary once to surface exec-format/glibc errors early","Keep the standalone install script as the documented fallback"],"tags":["npm","install","network","postinstall"],"backgroundTag":null,"analyzedSha":"8c5296ac459e8252d3cd702f3fbcbb0c249d95d5","analyzedAt":"2026-08-16T08:01:58.794Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}