{"record":{"id":"641e38b463d20222","repo":"heygen-com/hyperframes","slug":"build-zip-zip-formatbytes-zippedbytes-exceed","errorCode":null,"errorMessage":"[build-zip] zip ${formatBytes(zippedBytes)} exceeds ZIP size limit ${formatBytes(opts.maxZippedBytes)}.","messagePattern":"\\[build-zip\\] zip (.+?) exceeds ZIP size limit (.+?)\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/aws-lambda/scripts/build-zip.ts","lineNumber":162,"sourceCode":"  // 5. Compute the unzipped size BEFORE zipping so we fail loud when over budget.\n  const unzippedBytes = directorySizeBytes(stagingDir);\n  console.log(`[build-zip] unzipped staging size: ${formatBytes(unzippedBytes)}`);\n  if (unzippedBytes > opts.maxUnzippedBytes) {\n    throw new Error(\n      `[build-zip] unzipped bundle ${formatBytes(unzippedBytes)} exceeds limit ${formatBytes(\n        opts.maxUnzippedBytes,\n      )} (Lambda ZIP ceiling: 250 MiB unzipped). ` +\n        `Switch --source to the lighter option, or move Chrome to a Lambda Layer.`,\n    );\n  }\n\n  // 6. Build the ZIP.\n  const zipPath = join(distDir, \"handler.zip\");\n  zipDirectory(stagingDir, zipPath);\n  const zippedBytes = statSync(zipPath).size;\n  console.log(`[build-zip] zip size: ${formatBytes(zippedBytes)} → ${zipPath}`);\n  if (zippedBytes > opts.maxZippedBytes) {\n    throw new Error(\n      `[build-zip] zip ${formatBytes(zippedBytes)} exceeds ZIP size limit ${formatBytes(\n        opts.maxZippedBytes,\n      )}.`,\n    );\n  }\n\n  // 7. Sidecar manifest.\n  const manifest = {\n    builtAt: new Date().toISOString(),\n    durationMs: Date.now() - start,\n    source: opts.source,\n    unzippedBytes,\n    zippedBytes,\n    maxUnzippedBytes: opts.maxUnzippedBytes,\n    maxZippedBytes: opts.maxZippedBytes,\n  };\n  writeFileSync(join(distDir, \"handler.zip.manifest.json\"), JSON.stringify(manifest, null, 2));\n","sourceCodeStart":144,"sourceCodeEnd":180,"githubUrl":"https://github.com/heygen-com/hyperframes/blob/c2996c8626135db5253519359d8a063d3bafad8d/packages/aws-lambda/scripts/build-zip.ts#L144-L180","documentation":"After zipping, the build checks the compressed handler.zip size against opts.maxZippedBytes (default 150 MiB). This is an early-warning guard for bundle-size regressions, set to flag a sudden increase without false-failing on the natural ~100 MiB sparticuz + ffmpeg payload.","triggerScenarios":"The final handler.zip is larger than maxZippedBytes. Happens with chrome-headless-shell source or when dependencies have grown significantly since the guard threshold was set.","commonSituations":"New dependencies inflating the bundle; using the heavier Chrome source; uncompressed or poorly compressing binaries in staging.","solutions":["Switch to --source=sparticuz to reduce the zip size.","Move large binaries (Chrome, ffmpeg) to a Lambda Layer.","Raise --max-zipped=<bytes> if your deploy path (S3) supports a larger zip and the increase is intentional and reviewed."],"exampleFix":"// before\ntsx build-zip.ts --source=chrome-headless-shell\n\n// after\ntsx build-zip.ts --source=sparticuz","handlingStrategy":"validation","validationCode":"import { statSync } from \"node:fs\";\nconst zipBytes = statSync(zipPath).size;\nconst MAX_ZIPPED = 150 * 1024 * 1024;\nif (zipBytes > MAX_ZIPPED) {\n  console.error(`Zip ${zipBytes} exceeds limit ${MAX_ZIPPED}. Reduce bundle or use a Lambda Layer.`);\n  process.exit(1);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Track zip size across builds as a regression metric.","Use --source=sparticuz to keep the zip well under the threshold.","Set --max-zipped deliberately, not as a workaround for bloat."],"tags":["aws-lambda","size-limit","build","deployment"],"backgroundTag":null,"analyzedSha":"c2996c8626135db5253519359d8a063d3bafad8d","analyzedAt":"2026-08-12T22:18:56.877Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}