{"record":{"id":"6023f72b5c5af885","repo":"heygen-com/hyperframes","slug":"failed-to-bundle-beat-analyzer","errorCode":null,"errorMessage":"Failed to bundle beat analyzer","messagePattern":"Failed to bundle beat analyzer","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/cli/src/beats/headlessAnalyzer.ts","lineNumber":52,"sourceCode":"  const esbuild = await import(\"esbuild\");\n  const coreRoot = dirname(require.resolve(\"@hyperframes/core/package.json\"));\n  const entry = join(coreRoot, \"src/beats/beatDetection.ts\");\n  const result = await esbuild.build({\n    stdin: {\n      contents:\n        `import { analyzeMusicFromBuffer } from ${JSON.stringify(entry)};\\n` +\n        `globalThis.__hfAnalyze = analyzeMusicFromBuffer;`,\n      resolveDir: coreRoot,\n      loader: \"ts\",\n    },\n    bundle: true,\n    format: \"iife\",\n    platform: \"browser\",\n    target: \"es2020\",\n    write: false,\n  });\n  const out = result.outputFiles?.[0];\n  if (!out) throw new Error(\"Failed to bundle beat analyzer\");\n  return out.text;\n}\n\nfunction buildAnalyzerBundle(): Promise<string> {\n  if (bundlePromise) return bundlePromise;\n  bundlePromise = (async () => {\n    const prebuilt = findPrebuiltBundle();\n    if (prebuilt) return readFileSync(prebuilt, \"utf8\");\n    return buildFromCoreSource();\n  })().catch((err) => {\n    bundlePromise = null; // don't poison the process with a cached rejection\n    throw err;\n  });\n  return bundlePromise;\n}\n\nexport interface HeadlessBeatResult {\n  beatTimes: number[];","sourceCodeStart":34,"sourceCodeEnd":70,"githubUrl":"https://github.com/heygen-com/hyperframes/blob/c2996c8626135db5253519359d8a063d3bafad8d/packages/cli/src/beats/headlessAnalyzer.ts#L34-L70","documentation":"Thrown by buildFromCoreSource() when esbuild.build() returns no outputFiles, which should not happen under normal operation — esbuild returns at least one output for a valid build. It indicates a degenerate esbuild result (empty output array) when bundling the beat-detection entry from @hyperframes/core source at runtime. This path runs only when no prebuilt bundle artifact (beat-analyzer.global.js) is found on disk.","triggerScenarios":"analyzeBeatsHeadless() is called in a dev/monorepo context where findPrebuiltBundle() returns null, so buildAnalyzerBundle() calls buildFromCoreSource(); esbuild then returns an empty outputFiles array. Typically an esbuild version incompatibility or a malformed stdin entry.","commonSituations":"Running the CLI from source in the monorepo after @hyperframes/core's beatDetection.ts moved or was renamed; an esbuild upgrade changed output semantics; the entry path join(coreRoot, 'src/beats/beatDetection.ts') no longer resolves but esbuild returned an empty result instead of erroring.","solutions":["Run `bun run build` to regenerate the prebuilt beat-analyzer.global.js artifact so the runtime bundling path is not taken.","Verify @hyperframes/core/src/beats/beatDetection.ts exists and exports analyzeMusicFromBuffer; if it moved, update the entry path in buildFromCoreSource().","Reinstall dependencies (`bun install`) to ensure esbuild is at the expected version."],"exampleFix":"# before — no prebuilt bundle, esbuild returns empty\n$ bunx hyperframes beats track.mp3\n# build the artifacts so the prebuilt path is used\n$ bun run build\n$ bunx hyperframes beats track.mp3","handlingStrategy":"try-catch","validationCode":"import { existsSync } from 'node:fs';\nfunction prebuiltBundlePresent(): boolean {\n  // Mirror findPrebuiltBundle candidates relevant to your install\n  return existsSync(require('path').join(__dirname, 'beat-analyzer.global.js'));\n}\nif (!prebuiltBundlePresent()) {\n  console.warn('No prebuilt beat analyzer bundle — run `bun run build` before using the beats command.');\n}","typeGuard":null,"tryCatchPattern":"try {\n  await analyzeBeatsHeadless(buf);\n} catch (err) {\n  if (/Failed to bundle beat analyzer/i.test((err as Error).message)) {\n    console.error('Beat analyzer bundle could not be built. Run `bun run build` and retry.');\n  }\n  throw err;\n}","preventionTips":["Always run `bun run build` after pulling changes to regenerate the prebuilt analyzer bundle.","In CI, build before invoking the beats command so the runtime esbuild path is never taken.","Pin the esbuild version via the lockfile to avoid output-shape regressions."],"tags":["beats","esbuild","build","internal","monorepo"],"backgroundTag":null,"analyzedSha":"c2996c8626135db5253519359d8a063d3bafad8d","analyzedAt":"2026-08-12T22:18:56.877Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}