mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-14 13:27:13 +00:00
The producer bundle is emitted as ESM. The existing banner already shimmed
`require` via createRequire so CJS dep `require("fs")` calls work, but it
did NOT shim the CommonJS `__dirname` / `__filename` globals.
A bundled CJS dep (the ffmpeg/Emscripten wasm glue) references bare
`__dirname` to locate the wasm side-file — e.g. `scriptDirectory = __dirname
+ "/"` — and crashed at render time with:
ReferenceError: __dirname is not defined in ES module scope
This affects every render through producer (not just w2h), and only
manifests on first render of a fresh checkout where the producer hasn't
been rebuilt with the shim.
The fix reconstructs both globals from import.meta.url inside the esbuild
banner, alongside the existing `require` shim. No behavior change for code
that doesn't reference __dirname; correctly resolves the CJS contract for
code that does.
Verified by re-running a producer render after rebuild — completes through
ffmpeg without the ReferenceError.