{"record":{"id":"b00dc335c6dfbb0a","repo":"heygen-com/hyperframes","slug":"build-zip-npm-install-into-staging-failed-statu","errorCode":null,"errorMessage":"[build-zip] npm install into staging failed (status ${result.status})","messagePattern":"\\[build-zip\\] npm install into staging failed \\(status (.+?)\\)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/aws-lambda/scripts/build-zip.ts","lineNumber":283,"sourceCode":"  };\n  if (source === \"sparticuz\") {\n    (pkg.dependencies as Record<string, string>)[\"@sparticuz/chromium\"] =\n      readDepVersion(\"@sparticuz/chromium\");\n  }\n  writeFileSync(join(stagingDir, \"package.json\"), JSON.stringify(pkg, null, 2));\n\n  // --no-package-lock so we don't pollute staging with a lockfile we don't\n  // ship; --no-audit/--no-fund just for log noise.\n  const result = spawnSync(\n    \"npm\",\n    [\"install\", \"--no-package-lock\", \"--no-audit\", \"--no-fund\", \"--omit=dev\", \"--omit=optional\"],\n    {\n      cwd: stagingDir,\n      stdio: \"inherit\",\n    },\n  );\n  if (result.status !== 0) {\n    throw new Error(`[build-zip] npm install into staging failed (status ${result.status})`);\n  }\n  console.log(`[build-zip] staged node_modules via npm install`);\n}\n\nfunction readDepVersion(moduleName: string): string {\n  // Resolve the EXACT version bun installed into the workspace, not the\n  // semver range declared in package.json. The staging-dir npm install\n  // runs with `--no-package-lock`, so a caret range would float to the\n  // latest registry version at build time — diverging from what the\n  // workspace tests ran against and breaking ZIP-content determinism\n  // across consecutive builds. The lockfile pin gives us reproducibility.\n  const lockText = readFileSync(join(monorepoRoot, \"bun.lock\"), \"utf-8\");\n  // bun.lock lines look like:\n  //   \"puppeteer-core\": [\"puppeteer-core@24.43.1\", \"\", { ... }, \"sha512-...\"],\n  const re = new RegExp(\n    `\"${moduleName.replace(/[.*+?^${}()|[\\]\\\\]/g, \"\\\\$&\")}\":\\\\s*\\\\[\"${moduleName.replace(\n      /[.*+?^${}()|[\\]\\\\]/g,\n      \"\\\\$&\",","sourceCodeStart":265,"sourceCodeEnd":301,"githubUrl":"https://github.com/heygen-com/hyperframes/blob/c2996c8626135db5253519359d8a063d3bafad8d/packages/aws-lambda/scripts/build-zip.ts#L265-L301","documentation":"The staging step runs 'npm install --no-package-lock --no-audit --no-fund --omit=dev --omit=optional' inside the staging directory to populate node_modules with production deps. If npm exits non-zero, the build aborts because a partial install would ship a broken or incomplete zip.","triggerScenarios":"npm install exits non-zero — caused by network or registry errors, an unresolvable dependency version, a broken package.json in staging, npm not found on PATH, or a postinstall script failure.","commonSituations":"CI without network access; a transitive dependency was unpublished or yanked; npm cache corruption; npm not installed in the build Docker image.","solutions":["Run the same npm install command manually in the staging directory to see the error output.","Check network and registry connectivity from the build environment.","Clear the npm cache: npm cache clean --force.","Verify npm is installed and on PATH in the build container.","Check that the staged package.json has valid, resolvable dependency versions."],"exampleFix":null,"handlingStrategy":"retry","validationCode":"import { spawnSync } from \"node:child_process\";\nconst check = spawnSync(\"npm\", [\"--version\"], { encoding: \"utf-8\" });\nif (check.status !== 0) {\n  console.error(\"npm is not available on PATH. Install Node.js/npm first.\");\n  process.exit(1);\n}","typeGuard":null,"tryCatchPattern":"try {\n  // ... staging npm install logic ...\n} catch (e) {\n  if (e instanceof Error && e.message.includes(\"npm install into staging failed\")) {\n    console.error(\"npm install failed. Check network and registry. Retrying...\");\n    // retry once with a clean npm cache\n  }\n  throw e;\n}","preventionTips":["Ensure the build environment has network access to the npm registry.","Pin dependency versions in package.json to avoid unresolvable ranges.","Pre-warm the npm cache in CI Docker images."],"tags":["npm","build","dependencies","network"],"backgroundTag":null,"analyzedSha":"c2996c8626135db5253519359d8a063d3bafad8d","analyzedAt":"2026-08-12T22:18:56.877Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}