Skip to content

fix(producer): shim CJS __dirname / __filename in ESM banner#1445

Closed
ukimsanov wants to merge 1 commit into
mainfrom
fix/producer-esm-dirname-shim
Closed

fix(producer): shim CJS __dirname / __filename in ESM banner#1445
ukimsanov wants to merge 1 commit into
mainfrom
fix/producer-esm-dirname-shim

Conversation

@ukimsanov

@ukimsanov ukimsanov commented Jun 14, 2026

Copy link
Copy Markdown
Collaborator

Summary

Bundled CJS deps — notably the ffmpeg/Emscripten wasm glue, which does scriptDirectory = __dirname + "/" — were crashing at render time with __dirname is not defined in ES module scope.

The existing banner shimmed require from import.meta.url but missed __dirname / __filename. Adds both globals alongside the existing createRequire shim.

Verification

  • Verified by re-running a producer render after rebuild — ffmpeg pipeline completes cleanly
  • node packages/producer/build.mjs esbuild bundles complete without errors

Sibling PRs in this stack

All three independent; merge order doesn't matter.

Test plan

  • bun run --filter @hyperframes/producer build passes
  • Producer render of an existing project completes without __dirname errors

Bundled CJS deps — notably the ffmpeg/Emscripten wasm glue, which does
`scriptDirectory = __dirname + "/"` — were crashing at render time with
`__dirname is not defined in ES module scope`. The existing banner shimmed
`require` from `import.meta.url` but not `__dirname` / `__filename`.

Adds both globals from `import.meta.url` alongside the createRequire shim.
Verified by re-running a producer render after rebuild — ffmpeg pipeline
completes cleanly.
@ukimsanov ukimsanov force-pushed the fix/producer-esm-dirname-shim branch from da7b45c to 122b922 Compare June 14, 2026 23:49
@ukimsanov

Copy link
Copy Markdown
Collaborator Author

Closing — verified the bug only fires when the producer is loaded via Node (Bun is permissive about __dirname in ESM scope). Internal team usage is Bun-first per CLAUDE.md + CI is on Bun, so no one currently hits it. Re-open if an external npx hyperframes user reports the crash from Node.

@ukimsanov ukimsanov closed this Jun 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant