From 122b92281348b441df92ea72d3927a7aa7d1bb40 Mon Sep 17 00:00:00 2001 From: ukimsanov Date: Sun, 14 Jun 2026 14:59:57 -0700 Subject: [PATCH] fix(producer): shim CJS __dirname / __filename in ESM banner MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- packages/producer/build.mjs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/packages/producer/build.mjs b/packages/producer/build.mjs index 22fceae09..dedf32841 100644 --- a/packages/producer/build.mjs +++ b/packages/producer/build.mjs @@ -15,12 +15,16 @@ mkdirSync("dist", { recursive: true }); const scriptDir = dirname(fileURLToPath(import.meta.url)); -// The banner provides a real `require` function via createRequire so that -// esbuild's CJS interop (__require) works correctly in ESM output. -// Without this, bundled CJS deps (recast, yauzl, etc.) that call -// require("fs") throw "Dynamic require of 'fs' is not supported". +// Shim `require` + `__dirname` / `__filename` for bundled CJS deps that expect them in ESM scope. const cjsBanner = { - js: "import { createRequire as __cjsRequire } from 'module'; const require = __cjsRequire(import.meta.url);", + js: [ + "import { createRequire as __cjsRequire } from 'module';", + "import { fileURLToPath as __fileURLToPath } from 'url';", + "import { dirname as __pathDirname } from 'path';", + "const require = __cjsRequire(import.meta.url);", + "const __filename = __fileURLToPath(import.meta.url);", + "const __dirname = __pathDirname(__filename);", + ].join(" "), }; const workspaceAliasPlugin = {